Create customer money
When updating the customer money via the CustomerStatisticUpdater class, a customer money instance will be automatically created, if it does not currently exist for the specified customer and currency. If you need to manually create customer money for another scenario, see the example below. For more information about the CustomerStatisticUpdater class, see For developers: Update the customer money.
You will be creating customer money in the following cases:
- When there are not any CustomerMoney records created for the customer, i.e. the customer has not any registered orders yet.
- When there is no CustomerMoney record for the currency of the current order.
To create customer money, 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.
- Get the order.
Get the specified order. For more information, see For developers: Query orders.
- Create new customer money.
Create a new instance of the CustomerMoney class by calling the CreateCustomerMoney method of the orders manager.
- Specify the details of the customer money.
Set the properties of the CustomerMoney instance.
- Associate the customer with the customer money.
To associate the customer with the customer money, set the Parent property of the CustomerMoney instance to the instance of the customer, and add the customer money to the CustomerMoney collection property of the Customer instance.
- Save the changes.
Save the changes to the manager.
Use the following code sample: