All Projects → bossanova808 → Commerceregisteroncheckout

bossanova808 / Commerceregisteroncheckout

Licence: other
ARCHIVED: SEE README Allow user registration during Craft Commerce V1 checkouts.

Projects that are alternatives of or similar to Commerceregisteroncheckout

Craft Neo
A Matrix-like field type for Craft CMS that uses existing fields
Stars: ✭ 387 (+1038.24%)
Mutual labels:  craftcms, craft-plugin
Plugin Installer
Composer installer for Craft CMS plugins
Stars: ✭ 22 (-35.29%)
Mutual labels:  craftcms, craft-plugin
Vanillaforums
DEPRECATED Single Sign On plugin for VanillaForums/jsConnect and CraftCMS
Stars: ✭ 14 (-58.82%)
Mutual labels:  craftcms, craft-plugin
Element Api
Create a JSON API/Feed for your elements in Craft.
Stars: ✭ 493 (+1350%)
Mutual labels:  craftcms, craft-plugin
Geomate
GeoMate is a friend in need for all things geolocation. IP to geo lookup, automatic redirects (based on country, continent, language, etc), site switcher... You name it.
Stars: ✭ 19 (-44.12%)
Mutual labels:  craftcms, craft-plugin
craft-entriessubset
Craft field type plugin that extends the core Entries field type to give extra settings
Stars: ✭ 27 (-20.59%)
Mutual labels:  craftcms, craft-plugin
Imager Craft
This plugin has been DEPRECATED. Check out Imager X instead.
Stars: ✭ 351 (+932.35%)
Mutual labels:  craftcms, craft-plugin
transcoder
DEPRECATED Transcode videos to various formats, and provide thumbnails of the video
Stars: ✭ 24 (-29.41%)
Mutual labels:  craftcms, craft-plugin
Falcon
Enables Xkey / Hash-Two / Surrogate Key caching with Craft 2.x. Very experimental.
Stars: ✭ 14 (-58.82%)
Mutual labels:  craftcms, craft-plugin
Contact Form
Add a simple contact form to your Craft CMS site.
Stars: ✭ 294 (+764.71%)
Mutual labels:  craftcms, craft-plugin
Commercemailer
ARCHIVED: For Craft Commerce. Makes it easy to create forms for sending carts, products and orders by email.
Stars: ✭ 8 (-76.47%)
Mutual labels:  craftcms, craft-plugin
Craft3 Templateselect
A fieldtype that allows you to select a template from the site templates folder.
Stars: ✭ 18 (-47.06%)
Mutual labels:  craftcms, craft-plugin
craft-retour
Retour allows you to intelligently redirect legacy URLs, so that you don't lose SEO value when rebuilding & restructuring a website
Stars: ✭ 32 (-5.88%)
Mutual labels:  craftcms, craft-plugin
Awesome
A collection of awesome Craft CMS plugins, articles, resources and shiny things.
Stars: ✭ 449 (+1220.59%)
Mutual labels:  craftcms, craft-plugin
routemap
DEPRECATED Returns a list of Craft/Vue/React route rules and entry & asset URLs for ServiceWorkers from Craft entries
Stars: ✭ 27 (-20.59%)
Mutual labels:  craftcms, craft-plugin
Seomatic
DEPRECATED A turnkey SEO implementation for Craft CMS 2.x that is comprehensive, powerful, and flexible
Stars: ✭ 366 (+976.47%)
Mutual labels:  craftcms, craft-plugin
dospaces
DigitalOcean Spaces integration for Craft CMS
Stars: ✭ 31 (-8.82%)
Mutual labels:  craftcms, craft-plugin
craft.doxter
Markdown editor and parser for Craft CMS
Stars: ✭ 80 (+135.29%)
Mutual labels:  craftcms, craft-plugin
craft-recipe
A comprehensive recipe FieldType for Craft CMS that includes metric/imperial conversion, portion calculation, and JSON-LD microdata support
Stars: ✭ 23 (-32.35%)
Mutual labels:  craftcms, craft-plugin
Craft Emptycoalesce
Empty Coalesce adds the ??? operator to Twig that will return the first thing that is defined, not null, and not empty
Stars: ✭ 24 (-29.41%)
Mutual labels:  craftcms, craft-plugin

THIS PLUGIN IS ARCHIVED

Given Craft Commerce 2 now natively supports registration on checkout (see https://github.com/craftcms/commerce/issues/472) - this plugin will not be ported by me to Craft 3 / Commerce 2 (although before this official support came along, Foster Commerce did in fact port it over - thanks folks!).

It remains here for anyone still using it with Commerce V1 or for reference if you find the Commerce V2 implementation not enough - but there will be no more support or updates.

Commerce Register on Checkout plugin for Craft CMS

Register customers on checkout with Craft Commerce

Installation

To install Commerce Register on Checkout (CROC), follow these steps:

  1. Downloaded the latest release
  2. Unzip and copy the plugin folder commerceregisteroncheckout to your craft/plugins folder
  3. Install plugin in the Craft Control Panel under Settings > Plugins
  4. N.B. The plugin folder should be named commerceregisteroncheckout for Craft to see it.

Commerce Register on Checkout has been tested with Craft 2.6+ and Commerce 1.1+, and is in daily use on working, live stores.

Commerce Register on Checkout Overview

This plugin allows you to more easily add user registration as part of your Commerce checkout process.

Currently only allows for registering users with their username set to their email - however given commerce keys everything by the email, this is the most natural set up anyway.

As of 0.0.6+ it also transfers address records and sets the last used billing and shipping address IDs so that the newly created Craft Users immediately get access to their address records in their address book for their next order (this does not occur if you integrate a standard Craft registration form).

Why Not Use A Standard Craft Registation Form?

An easy solution to this issue is to present a mostly pre-filled form to the user immediately following checkout - and of course this works fine and means one less plugin, which is a good thing. However, from a business perspective and based on real world experience, you will see vastly lower user registration numbers with this method.

See discussion here: https://craftcms.stackexchange.com/questions/18974/register-a-user-as-part-of-a-commerce-checkout/18993#18993

In short, this plugin allows for a more integrated approach - registering the user during the actual checkout, which signifcantly increases the number of users that will register, and this has many potential business benefits of course.

In addition, if you use a standard registration form, your customers will need to re-enter their address details when they do their second order as these are not automatically transferred with the registration (order records are, but not addresses). This is less than ideal from a UX perspective.

Configuring Commerce Register on Checkout

You can turn on some extra logging in the plugin settings - it's probably fine to leave this on even on your live server - it just logs all successful user registrations in addition to any errors/warnings.

Using Commerce Register on Checkout

At any point in your checkout flow before the final payment/order completion, you need to make one additional POST request. I do this by ajax just before the payment form is submitted.

This request must post the users desired password to the saveRegistrationDetails controller. This password is then encrypted using Craft's built in encryption mechanisms, and saved along with the order number to a temporary database record.

It's very simple, here's some sample code:

HTML Form:

<input type="checkbox" value="true" id="registerUser" name="registerUser" checked>
<input type="password" value="" placeholder="New Password (min. 6 characters)" name="password">

JS:

Somehere in e.g. your master layout set a variable to the CSRF token value (if you're using CSRF verification):

    window.csrfTokenValue = "{{ craft.request.csrfToken|e('js') }}"

Then the JS you need is just something like this:

    // Has the customer chosen to register an account?
    if ($('#registerUser').prop('checked')) {
        var pw_value = $('input[type="password"]').val();
        var pw_error = '';
        // Validate the passwrod meets Craft's rules
        if (pw_value.length < 6) {
            pw_error = "Password length must be 6 or more characters";
        }
        if (pw_error) {
            alert(pw_error);
        }
        // Lodge the registration details for later retrieval
        else {
            $.ajax({
                type: 'POST',
                url: '/actions/commerceRegisterOnCheckout/saveRegistrationDetails',
                data: {
                    CRAFT_CSRF_TOKEN: window.csrfTokenValue,
                    password: pw_value,
                }
                complete: {
                    // NB! Your call to your payment function must 
                    // run only AFTER the registration details have been lodged
                    // So pop it here...
                    doPayment();
                }
            });
        }
    }
    // Register account not chosen, just do the actual payment...
    else {
        doPayment();
    }

(NB - as above you should also validate the password on the front end to make sure it meets Craft's minimum 6 character requirement, or the user registration later may fail).

doPayment is of course your own function that will actually submit your payment form.

The plugin then listens to the commerce_orders.onOrderComplete event. For each completed order it looks for a saved record, and if it finds one then registers the user. It will also immediately log them in, and assign them to the default user group, just like a normal user registration.

Handling Success & Errors

In your order complete template, you can check the results of the registration process and handle any errors - giving the user another chance to register if something went wrong, for example. The users account information is returned to the template in an account variable.

Here's some sketch code to get you started:


    {# Get the results of user registration, if there are any... #}
    {% set registered = craft.commerceRegisterOnCheckout.checkoutRegistered ?? null %}
    {% set account = craft.commerceRegisterOnCheckout.checkoutAccount ?? null %}

    {# Explicitly clear the http session variables now that we've used them #}
    {% do craft.commerceRegisterOnCheckout.clearRegisterSession %}


    {# Was registration attempted? #}
    {% if registered is not null %}

        {# Success, if true #}
        {% if registered %}
            <do some stuff>
        
        {# Failure, otherwise #}
        {% else %}
            {% if account|length %}
                {% if "has already been taken" in account.getError('email') %}

                ... Point out they are already registered...
                
            {% else %}
                ...etc, e.g. present a user registration form with as much filled in as possible>
            }

Events

CROC offers an event before attempting to save the new user onBeforeRegister, and on the completion of succesful user registration onRegisterComplete.

The event parameters for both events are the Order and User models.

You can listen and act on these events if needed, e.g.:


        craft()->on('commerceregisteroncheckout.onBeforeRegister', function($event){

            $order = $event->params['order'];
            $user = $event->params['user'];

            ...etc

        }


        craft()->on('commerceregisteroncheckout.onRegisterComplete', function($event){

            $order = $event->params['order'];
            $user = $event->params['user'];

            ...etc

        }

Commerce Register on Checkout Changelog

See releases.json

Who is to blame?

Brought to you by Jeremy Daalder

Issues?

Please use github issues or find me on the Craft slack, I mostly hang out in the #commerce channel

Icon

by IconfactoryTeam from the Noun Project

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].