How to troubleshoot/fix a missing product in PLP (Product Listing Page)
September 24th 2021
Missing Products in PLP is one of the most common issues faced by Sitecore Commerce developers.
In this Blog Post I will list some of the frequent reasons leading to this behavior and how to mitigate them.
P.S: In this Blog Post we cover the scenario where PLP is showing products but only a few are missing. Not the scenario where PLP is not showing at all. There are several posts about this later scenario. The scenarios below apply to Sitecore Commerce 9.3
1) Product Not in Solr Web index:
-Go to Solr console admin and execute below query.
-Check the results to see if the product exist in the expected path (Category)
-If missing, it means the product wasn't properly indexed.
Fix:
-Run Full Catalog Index Minion from Postman
Or
-Disassociate/Reassociate SellableItem from a Parent Category in Bizfx.
2) Product List Cache:
Product is properly indexed, but still not showing in the PLP.
Cache is another reason, this might happen.
If you want the product to show immediately you need to clear this cache.
Fix:
-One way to fix this is by using a clearcache.aspx file with following code example:
<%@ Import Namespace="System" %>
<%@ Import Namespace="Sitecore.DependencyInjection" %>
<%@ Import Namespace="Microsoft.Extensions.DependencyInjection" %>
<%@ Import Namespace="Sitecore.Commerce.Engine.Connect" %>
<%@ Import Namespace="Sitecore.Commerce.Engine.Connect.DataProvider" %>
<script language="C#" runat="server">
public void Page_Load(object sender, EventArgs e)
{
ServiceLocator.ServiceProvider.GetService<CachingRepository>().Clear();
new CatalogRepository("en").UpdateMappingEntries(DateTime.UtcNow);
EngineConnectUtility.RefreshSitecoreCaches("web");
}
</script>
Cache is cleared.
-Another option is to trigger a Re-Index. This should also clear the cache.
3) Mappings in Memory Cache out of date:
Now, let's get to the reason I'm writing this blog post. An interesting scenario I faced recently.
Let's start with a quick introduction about Catalog Mappings in Sitecore Commerce.
Catalog Mappings are used to map a Catalog/Category/SellableItem Entity Id to Sitecore Ids in the Content Tree.
It's 1 to many relationship, as 1 SellableItem Enity can map to many Sitecore Items based on Category/Catalog associations.
A product associated with Books category and Sale category results in 2 items in Sitecore Content Tree.
Catalog Mappings are stored in Mappings table of Shared Database, but Catalog Data Provider (Sitecore Commerce Engine Connect) keeps them in a memory cache as well.
On the CM this cache can be cleared from the 'Commerce' ribbon, but on the CD, this cache is only cleared after an indexing job is completed, triggered by indexing:completed:remote
event.
Let's now get to the issue in hand.
If you use DotPeek or any decompiler to take a peek at Sitecore.Commerce.Engine.Connect.Events.IndexingCompletedEventHandler you will notice the piece of code below:
if (completedEventArgs.SitecoreIds.Length > CommerceEngineConfiguration.Instance.FullCacheRefreshThreshold || this.IsStandaloneEnvironment())
{
Log.Info("OnIndexingCompleted - Performing full cache refresh.", (object) this);
CacheManager.ClearAllCaches();
}
else
{
Log.Info("OnIndexingCompleted - Performing incremental cache updates.", (object) this);
Dictionary<string, Item> dictionary = new Dictionary<string, Item>();
CatalogRepository catalogRepository = new CatalogRepository("en");
foreach (string sitecoreId1 in completedEventArgs.SitecoreIds)
{
string sitecoreId = sitecoreId1;
ID result;
if (ID.TryParse(sitecoreId, out result))
{
catalogRepository.ClearCatalogMappings(sitecoreId);
MappingEntry mappingEntry = catalogRepository.GetMappingEntry(sitecoreId);
As you can see, if the number of Sitecore Ids processed by the index is > the treshold, the catalog mappings is not being cleared. Causing any new association between a sellable Item and Category to be ignored, and not displayed on the PLP.
Now, that treshold is coming from Config, but only if you applied following Hotfix Rollup Package: https://support.sitecore.com/kb?id=kb_article_view&sysparm_article=KB0963029
If not it would be hardcoded.
For this Post, we'll assume you applied the hotfix.
When I applied the hotfix above I used the value suggested '20'.
After troubleshooting the missing products issue, I realized we had some products associated with more than 20 categories. In which scenario Mappings wouldn't be cleared for these products, and they end up missing from one or more categories.
Fix:
Unfortunately ClearCatalogMappings method is internal and can't be called from external code. So a *.aspx file that can be called on demand to clear mappings is out of the table.
The alternative fix is to simply increase the threshold config: /sitecore/commerceEngineConfiguration/fullCacheRefreshThreshold
In my case, increasing it to 100 fixed the problem.
I hope you find this post helpful if you find yourself in a similar situation.
Feel free to leave comments or questions.
Comments