Blog

Create a new Customer Entity in Sitecore Commerce 9.x

14th March 2019

Sitecore

Sitecore Commerce

If you are looking to create a new customer entity in Sitecore Commerce 9.x, this is the post for you. I spent some time searching for code using my friend Google but couldn't find much. Hope this helps.

First, setup a new pipeline which accepts an object with values to create a new customer, make sure the output is of type Customer. This is crucial as we will pass the resulting customer to the persist block.

public void ConfigureServices(IServiceCollection services)
{
var assembly = Assembly.GetExecutingAssembly();
services.RegisterAllPipelineBlocks(assembly);
services.Sitecore().Pipelines(config => config
.AddPipeline<ICreateCustomerMinionPipeline, CreateCustomerMinionPipeline>(configure =>
{
configure.Add<CreateCustomersBlock>().Add<PersistCustomerBlock>().Add<PersistCustomerIdIndexBlock>();
})
);
//hopefully we create a new customer entity in the CreateCustomersBlock which is our code, followed by the PersistCustomerBlock and the PersistCustomerIdIndexBlock which will save our new customer.
services.RegisterAllCommands(assembly);
}

In the next blog post we will look at indexing custom attributes for entities so that we can search by custom attributes. Hopefully your code search brings you to this post and I hope this blog post helps in some way.

If you have any questions or concerns, please get in touch with me. (@akshaysura13 on twitter or on Slack).