Customizing creation of new customers

In Kentico, you can modify the way of creating new customers. That is suitable especially when you want to process additional actions during creation of a new customer, or when you want to replace the process of creation new customers completely.

To customize creating of new customers, you need to implement a class that inherits from the CustomerInfoProvider class:

  1. Create a new class in your project in Visual Studio (for example CustomCustomerInfoProvider.cs) that inherits from the CustomerInfoProvider class and registers the custom InfoProvider:

     [assembly: RegisterCustomProvider(typeof(CustomCustomerInfoProvider))]
     public class CustomCustomerInfoProvider : CustomerInfoProvider
  2. Implement a method that overrides the default SetCustomerInfoInterval method:

    See an example below.

  3. Save your project and reload you Kentico website.

If you open your website, Kentico uses the modified CustomerInfoProvider class with the modified methods.

To customize retrieving of a customer, you can similarly customize the GetCustomerInfoInternal method.

To customize deleting of a customer, you can similarly customize the DeleteCustomerInfoInternal method.

Example – Adding extra credit to newly registered customers

This example demonstrates adding extra credit to the credit account of every newly registered customer.

using System;
using CMS;
using CMS.Ecommerce;
using CMS.SiteProvider;

[assembly: RegisterCustomProvider(typeof(CustomCustomerInfoProvider))]
public class CustomCustomerInfoProvider : CustomerInfoProvider
    protected override void SetCustomerInfoInternal(CustomerInfo customerObj)
        // Remembers whether a new customer is created.
        bool newCustomer = ((customerObj != null) && (customerObj.CustomerID <= 0));

        // Updates a customer or creates a new customer based on the default process.

        // Adds extra credit for each new registered customer.
        if (newCustomer && customerObj.CustomerIsRegistered)
            // Initializes a credit event.
            CreditEventInfo extraCredit = new CreditEventInfo();

            // Sets the credit event general properties.
            extraCredit.EventName = "Extra credit for a new customer";
            extraCredit.EventDate = DateTime.Now;
            extraCredit.EventDescription = "This is a starting credit for a new customer.";
            extraCredit.EventCustomerID = customerObj.CustomerID;

            // Sets the credit event value in the site main currency.
            extraCredit.EventCreditChange = 100;

            // Sets credit as site credit or as global credit according to the settings.
            extraCredit.EventSiteID = ECommerceHelper.GetSiteID(SiteContext.CurrentSiteID, ECommerceSettings.USE_GLOBAL_CREDIT);

            // Saves the credit event.