Git Product home page Git Product logo

commerceregisteroncheckout's Introduction

THIS PLUGIN IS ARCHIVED

Given Craft Commerce 2 now natively supports registration on checkout (see craftcms/commerce#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

commerceregisteroncheckout's People

Contributors

bossanova808 avatar msbit avatar philipzaengle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

commerceregisteroncheckout's Issues

FR: Allow registration after order is placed

In the current checkout workflow, we provide a (non-plugin based) ajax registration form on the order confirmation page (along with an order-invoice), with pre-filled hidden fields for firstName, lastName, and email from the order, so that all the user needs to enter is password. However, as you mention, the shipping and billing address is not currently saved to the customer account. Thus the interest in this great plugin.

However, if I understand correctly, this plugin will only work if registration is done during the checkout process, before payment is completed? It would be great if it would also work after the checkout process is completed, or anytime that there is a 'order' model available.

fyi... this is for a craft 3/commerce 2 implementation (you don't seem to have 'Issues' enabled for that fork.)

Custom DB prefix not working

I just wanted to install the plugin but got the following error message:
CDbCommand failed to execute the SQL statement: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'd0227279.craft_commerceregisteroncheckout' doesn't exist

In my config/db.php I set a custom prefix, which is not 'craft' - it seems like the plugins does not take care of this.

Error after plugin install

This plugin looks like exactly what I need, but I've run into an error.

After installing the plugin but before any code has been added to the templates, this error happens when going through the checkout process on a fresh install of Craft Commerce (version 2.6.2959).

CDbCommand failed to execute the SQL statement: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'craft.craft_commerceregisteroncheckout' doesn't exist. The SQL statement executed was: select * from craft_commerceregisteroncheckout where orderNumber='df410f931c1af96c06f88b3342146300'

This is on the shop/checkout/payment page.

Should I manually create the table it's asking for?

Duplicated entry on craft_commerce_customers table created

Hi Jeremy,

First of all, thanks for this handy plugin.
I'm experiencing an issue where it seems that 2 different entries are created in the "craft_commerce_customers" table.

The first entry seems to be the default craft behaviour and the "Last Billing Id" and "Last Shipping Id" get mapped to this customer.

The second entry seems to be the one created by the CommerceRegisterOnCheckout plugin and the UserId gets map to this entry.

Everything else seems working as expected where and the user gets created and mapped to the second entry although it doesn't have any Billing or Shipping info mapped to it.

Im using Craft CMS 2.6.2959, Commerce 1.2.1334, and Commerce Register on Checkout 0.0.3.

I also have Commerce Widgets 1.0.3 and Commerce Stock Notifier 1.0.0 but they shouldn't be affecting the process.

Please let me know if you need any more info to try and replicate the issue.

Thanks heaps,
Alberto

No one gets registered

The only log messages I get are: [Forced].

I am a bit confused. Using you sample code: how and when does the POST request get triggered? Don’t know where to start, really. Any pointers?

Support saving payment sources on register/checkout

In order to save payment sources on successful payment (for the gateways that support it), Craft Commerce requires to be logged in. Because this plugin creates the user after the payment, it cannot save payment sources.

Making this available for Craft3

This is not the best place to ask this but I am wondering what is involved in moving this to Craft3? I haven't migrated a plugin from 2 > 3 but this seems like a very useful plugin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.