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