Create customers

This example creates a customer by collecting the required information from the Sitefinity CMS user representing the customer. If you want to create a customer from an anonymous user, you have to modify the method to accept the required information as arguments.

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

  1. Get instances of the following managers:
    • Orders manager
    • User manager
    • User profile manager
  2. Get the user.
    Get the specified user. For more information, see For developers: Query users.
  3. Get the user profile.
    Get the user profile of the specified user. For more information, see For developers: Query user profiles.
  4. Validate the customer.
    Check whether a customer already exists for this user.
  5. Create a new customer.
    Create a new instance of the Customer class by calling the CreateCustomer method of the orders manager.
  6. Set the properties of the Customer instance.
    Set the properties to the respective values stored in the User instance and the SitefinityProfile instance.
  7. Associate the customer with the user.
    To associate the customer with the user, set the UserProfile and the UserProfileId properties of the Customer instance.
  8. 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?

Next article

Query customers