top of page
Search
Writer's pictureYassine Alahyane

Sitecore Experience Commerce - Catalog Entities to Sitecore Items Mapping



How to reset Catalog Entity Ids to Sitecore Item Ids Mappings

May 3rd 2021


I was going through an SXC 902 to 93 upgrade lately, and realized there was a big change in how Catalog Entities are mapped to Sitecore Items Ids in Content Editor:


SXC 9.0.2: Mappings are generated using Deterministic Ids and kept in Memory.

SXC 9.3 (Since 9.0.3) : Mappings are generated using Deterministic Ids and stored in DB Table.


Upon completing the Upgrade, I started having some issues with several products and categories.

After further investigation I found some mappings were corrupt.

Therefore, I started looking for a way to reset/regenerate those mappings based on the Catalog Entities currently in DB.


Looking closely at the following SQL Stored Procedures:

-CatalogUpdateMappings

-UpdateEntities

And the following Commerce Engine Pipeline: IUpdateEntitiesPipeline, I realized that a Catalog Entity Mappings are updated after each Update.


With this information in mind, All I needed is:


1-Delete all mappings from DB:


DELETE FROM [SitecoreCommerce930_SharedEnvironments].[sitecore_commerce_storage].[Mappings]

2-Create a custom Commerce Engine Endpoint to update all Catalog Entities:


A- Catalogs:


var catalogs = await this._commerceCommander.Pipeline<IFindEntitiesInListPipeline>().Run(new FindEntitiesInListArgument(typeof(Catalog), CommerceEntity.ListName<Catalog>(), 0, int.MaxValue),  context).ConfigureAwait(false);

var catalogArgList = catalogs.List.Items.Select(catalog => new PersistEntityArgument(catalog)).ToList();

await this._commerceCommander.Pipeline<IUpdateEntitiesPipeline>().Run(new PersistEntitiesArgument(catalogArgList), context).ConfigureAwait(false);

B-Categories:


var categories = await this._commerceCommander.Pipeline<IFindEntitiesInListPipeline>().Run(new FindEntitiesInListArgument(typeof(Category), CommerceEntity.ListName<Category>(), 0, int.MaxValue), context).ConfigureAwait(false);

var categoryArgList = categories.List.Items.Select(category => new PersistEntityArgument(category)).ToList();

await this._commerceCommander.Pipeline<IUpdateEntitiesPipeline>().Run(new PersistEntitiesArgument(categoryArgList), context).ConfigureAwait(false);

C-Sellable Items:


var sellableItems = await this._commerceCommander.Pipeline<IFindEntitiesInListPipeline>().Run(new FindEntitiesInListArgument(typeof(SellableItem), CommerceEntity.ListName<SellableItem>(), 0, int.MaxValue), context).ConfigureAwait(false);

var sellableItemsArgList = sellableItems.List.Items.Select(sellableItem => new PersistEntityArgument(sellableItem)).ToList();

await this._commerceCommander.Pipeline<IUpdateEntitiesPipeline>().Run(new PersistEntitiesArgument(sellableItemsArgList), context).ConfigureAwait(false);

After executing the above 2 steps, all the catalog mappings were regenerated properly and all issues were resolved.


I hope you find this post helpful if you fund yourself in a similar situation.



48 views0 comments

Recent Posts

See All

Комментарии


bottom of page