Sitecore Commerce Id Generation Helper Methods

Monday, February 25, 2019

If you've been working with Sitecore Experience Commerce, the chances are you've been using code like this to generate an entity id in the correct format.

var catalogId = $"{CommerceEntity.IdPrefix<Catalog>()}{catalogName}";
var categoryId = $"{CommerceEntity.IdPrefix<Category>()}{catalogName}-{categoryName}";

Well it turns out that there are some handy helper methods built into the product to make this a bit simpler, instead of having to compose the entity ID's yourself like above you can instead use the following:

var catalogId = catalogName.ToEntityId<Catalog>();
var categoryId = categoryName.ToCategoryId(catalogName);

A much cleaner way of handling that for sure!

comments powered by Disqus