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:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?

Next article

Query customers