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:

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?