Creating and linking Sitecore Commerce user to ECS

Sitecore commerce connect gives you the ability to create users and customers using the customer pipeline. I am going to talk about creating users and customers using the Customer pipeline and linking it to external commerce system user id.

Create User:

You will have to extend the pipeline to add a processor that will handle user creation in ECS.

The flow should be the following:

  1. Prepare the CreateUserRequest request object. Pass the username, password, email, name, etc fields
  2. Create a user in external commerce system (ECS) using the details in the request. This is the new processor that you have added to create user in ECS.
  3. In the same class, map the external id of the user (User Id generated in the ECS) to the property “UserId” in the request.
  4. The request is then passed to the processor CreateUserInSitecore. This class reads the propert “UserId” from the request and then links the sitecore user to Insite user.

Here is a snippet from the class that creates a user in ECS (in my case, Insite Commerce)

Depending on how your ECS handles guest user, you will have to implement it. Insite creates a user login for a guest user too.

Now, here is a scenario where you would want to create a user on the fly only in sitecore and link it to an existing user in ECS. If the user is already existing in ECS, then on login, you need to check if the user login fails in sitecore and user login succeeds in ECS. If that’s true, then call the createUser processor. Add a custom property in the request to indicate where to create user in ECS or Read existing user data from ECS and then create a user in sitecore.

Create Customer:

The create user flow holds true for the create customer also. Create a customer in ECS, then create a customer in Sitecore. Here is the how the ECS customer is linked to sitecore customer:

request.CommerceCustomer.ExternalId = ECSCustomerId