Customizing creation of new customers
In Kentico, you can customize how the system creates new customers. This is suitable especially when you want to process additional actions during the creation of a new customer, or when you want to replace the custom creation process completely.
To customize creating of new customers, you need to implement a class that inherits from the CustomerInfoProvider class:
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 { }
Override the default SetInfo method.
Save your project and reload your Kentico website.
The system now uses the custom CustomerInfoProvider class with the modified method.
To customize retrieval or deleting of customers, you can similarly customize the GetInfoByID or DeleteInfo methods.
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 SetInfo(CustomerInfo customerObj)
{
// Determines whether a new customer is being created
bool newCustomer = ((customerObj != null) && (customerObj.CustomerID <= 0));
// Updates or creates the customer based on the default process
base.SetInfo(customerObj);
// Adds extra credit for each new registered customer
if (newCustomer && customerObj.CustomerIsRegistered)
{
// Creates a new credit event object
CreditEventInfo extraCredit = new CreditEventInfo();
// Sets the credit event's general properties
extraCredit.EventName = "Extra credit for a new customer";
extraCredit.EventDate = DateTime.Now;
extraCredit.EventDescription = "This is starting credit for a new customer.";
extraCredit.EventCustomerID = customerObj.CustomerID;
// Sets the credit event's value in the site's main currency
extraCredit.EventCreditChange = 100;
// Sets the credit as site or global credit according to the current site's settings
extraCredit.EventSiteID = ECommerceHelper.GetSiteID(SiteContext.CurrentSiteID, ECommerceSettings.USE_GLOBAL_CREDIT);
// Saves the credit event to the database
CreditEventInfoProvider.SetCreditEventInfo(extraCredit);
}
}
}