Create a customer statistic

When updating a customer statistic via the CustomerStatisticUpdater class, a customer statistic will be automatically created, if it does not currently exist for the specified customer. If you need to manually create a customer statistic for another scenario, see the example below. For more information about the CustomerStatisticUpdater class, see For developers: Update the customer statistic.

To create a customer statistic, you have to perform the following:

  1. Get the orders managers:
    Get an instance of the OrdersManager object.
  2. Get the customer.
    Get the specified customer. For more information, see For developers: Query customers.
  3. Create new customer statistic.
    Create a new instance of the CustomerStatistic class by calling the CreateCustomerStatistic method of the orders manager.
  4. Associate the customer with the customer statistic.
    To associate the customer with the customer statistic, set the Statistic property of the Customer instance to the instance of the customer statistic, and set the StatisticId property of the Customer instance to the ID of the customer statistic
  5. Set the properties of the CustomerStatistic instance.
    Set the LastOrderDate, the LastOrderNumber, the OrdersCount and the LastModified properties to the appropriate values.
  6. Save the changes.
    Save the changes to the manager.

Use the following code sample:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?