How to create customer when user registers to site

   —   
This article shows how to automatically create customer when user registers to site using RegistrationForm web part.
You can create copy of Registration Form web part and into this copy add controls for user to enter data that you need to acquire (e.g. address). Then you can use sample code bellow to create new customer (in btnOK_Click method):

using CMS.Ecommerce;

//...

CustomerInfo ci = new CustomerInfo();
ci.CustomerFirstName = this.txtFirstName1.Text.Trim();
//...
ci.CustomerUserID = ui.UserID;
ci.CustomerEnabled = true;
ci.CustomerCreated = DateTime.Now;
CustomerInfoProvider.SetCustomerInfo(ci);


You can also inspire by code for customer creation in ~\CMSModules\Ecommerce\Controls\ShoppingCart\ShoppingCartCheckRegistration.ascx.cs (begins at line 759 in version 4.0) file and by code for address creation in ShoppingCartOrderAddresses.ascx.cs control (begins at line 939 in version 4.0).

See also:

Applies to: Kentico CMS with E-commerce
Share this article on   LinkedIn