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:

  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. Get the order.
    Get the specified order. For more information, see For developers: Query orders.
  4. Create new customer money.
    Create a new instance of the CustomerMoney class by calling the CreateCustomerMoney method of the orders manager.
  5. Specify the details of the customer money.
    Set the properties of the CustomerMoney instance.
  6. 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.
  7. 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?