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:
- Get the orders managers:
Get an instance of the OrdersManager object.
- Get the customer.
Get the specified customer. For more information, see For developers: Query customers.
- Create new customer statistic.
Create a new instance of the CustomerStatistic class by calling the CreateCustomerStatistic method of the orders manager.
- 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
- Set the properties of the CustomerStatistic instance.
Set the LastOrderDate, the LastOrderNumber, the OrdersCount and the LastModified properties to the appropriate values.
- Save the changes.
Save the changes to the manager.
Use the following code sample: