Sitecore E-Commerce Services Part 3 – Customer Accounts

Thursday, November 21, 2013 @ 10:42

Sitecore E-Commerce Services Part 3 – Customer Accounts

By: Dusty Eves, Senior Developer

So by now your user can add products to and from your cart, now time to go the full nine and give them the ability to purchase.

Customer Account

Anonymous checkout is an option for many sites but most are going to want to establish an account for the customer.  SES manages customer accounts as a Sitecore user account with customer specific defined roles.  SES has provided the constructs for account creation so the only thing that is on the implementer is wiring it up.  But before we do that we've a few configuration items to see to.

As previously mentioned SES customer accounts are managed as Sitecore user accounts.  Under the General settings items there's a field that defines the user groups to which new customer accounts are added upon creation.  For now set this to “extranet\Customer”.

The other proverbial T we need to cross is to setup the sites Countries.  Under Webshop Business Settings there is a childless countries node defining our E-Commerce countries.  Add a node underneath it.  Next under Webshop Site Settings/Business Catalog point the Country Link field to the aforementioned Countries node. 


This covers the settings that will cause the customer creation process to fail, but we've one other setting to which we must attend.  No self-respecting E-Commerce site would leave the user on the login or account creation page on completion so we need to define to where users are redirect.  This is defined by the My Page Link field under General Settings.


Page Setups

SES has most of the wiring we need for our account management, but as with most things in Sitecore it is the implementer to create the pages to which to wire it.  Underneath your MySite node create a folder called CustomerService.  Under the CustomerService node create a simple page for our customer service functions (in this tutorial, Create Account, Login, Change Password and Customer Info).  Once we've our pages we'll need sublayouts for them for all of the aforementioned pages plus a LoginStatus to serve as a header for all our pages.


Account Creation

The bare minimum information SES needs to create a customer account is an user name, an address and a password.  For our example, and as is the case in most sites, the user name an email address will be one and the same.  Start by setting up a simple form for account creation with the requisite fields.  Our customer functionality is wrapped in the ICustomerManager<CustomerInfo>.  Once we've instantiated the ICustomerManager we call the CreateCustomerAccount method passing in the name, email and password.  If the account creation is successful the method will return a CustomerInfo object. 

Before calling the CreateCustomerAccount method we need to first verify whether or not the account already exists.  Creating an account synonymous with one that already exists doesn't result in an exception condition but will will result in other unexpected behavior.  To check for the account call GetCustomerInfo from the customer manager and pass in the account name.  It will return a CustomerInfo object whether or not the customer exists, but if it not a valid existing customer the email address field will not be populated.

 While the CreateCustomerAccount method only takes a name and email address there's far more to a customers information than that.  To populate the other customer fields we can write to the CustomerInfo and pass it into the customer manager's UpdateCustomerProfileMethod.  This method is also used to update customer information both on creation as well as customer information maintenance page.  The last thing we want to do in our account creation is set the CustomerManager.CurrentUser to our newly created customer object and redirect them to our start page, leaving our newly created user logged in and ready to shop.

Login, Logout, and Login Status


Now that we've the account creation the users need the ability to log in and out which has again been wrapped for us in the ICustomerManager.  Start by creating a simple form for user name and password.  As previously stated SES manages customers as a type of Sitecore users so we need to pass in more than just the email address.  We need to pass in the fully qualified username inclusive of the domain.  To get the full name we call the GetFullName method of the Sitecore domain.  Once we've the username we just call the ICustomerManager.LogInCustomer method, from which we're returned a boolean indicating whether or not the login was successful.


Once we can login we need a mechanism to advise the user of their login status as well as logout.  The most common place to put such is in the header.  For the Login Status sublayout setup two separate panels, one with a prompt and a link to login and the other a panel advising them they're logged in and providing them with a logout button.  The display of either panel is controlled by whether or not a user is logged in.  To determine that the we call the Sitecore.Ecommerce.Utils.MainUtil.IsLoggedIn() method.  For our login link URL we pull the Main Login Link field from WebShop Site Settings General node.  To logout we call the logout method of the Sitecore Authentication Manager.


One thing of which to be aware when working with your login page, the login context for SES is the same as the Sitecore login context.  If you login on the e-commerce side and the go into the Sitecore backend you will likely get access denied errors.  To fix this just go to and again login as the admin user.

Change Passwords and Password Reset

Last thing you need for your customer is the ability to update and reset their passwords.  For both cases we use the same mechanisms for the ASP.NET membership provider.  For a password change we pull the membership of the E-Commerce context current user and for a password reset the username is a text field.

Logged In User