Customizing how products are categorized in the Strands integration

By default, Kentico uses document type IDs for categorizing products in the Strands integration — both in the Strands catalog feed and the Strands recommendations web part. To fully customize the categorization on both the places, you need to create a custom implementation of the IStrandsCatalogCategoryMapper interface. By customizing the categorization, you can have it better represent the structure of your site.

This page describes how you can create a custom class in which you perform such a customization. The page also provides two example customizations for you to build on.

Creating a custom Strands product categorization

  1. Open your web project in Visual Studio and create a new class in the App_Code folder (or CMSApp_AppCode -> Old_App_Code if the project is installed as a web application). For example, name the class CustomStrandsCatalogCategoryMapper.cs.

  2. Copy the following code into the class:

    
    
    
     using System;
     using System.Globalization;
    
     using CMS.Base;
     using CMS.Core;
     using CMS.StrandsRecommender;
     using CMS.DocumentEngine;
     using CMS.Ecommerce;
    
     [CustomStrandsCategoryMappingAttribute]
     public partial class CMSModuleLoader
     {
         private class CustomStrandsCategoryMappingAttribute : CMSLoaderAttribute
         {
             private class CustomStrandsCatalogCategoryMapper : IStrandsCatalogCategoryMapper
             {
                 public string GetItemCategory(TreeNode catalogItem)
                 {
                      // Body of your Strands catalog categorization customization method
                 }
             }
    
             /// <summary>
             /// Registers module methods.
             /// </summary>
             public override void Init()
             {
                 ObjectFactory<IStrandsCatalogCategoryMapper>.SetDefaultObjectTypeTo<CustomStrandsCatalogCategoryMapper>();
             }
         }
     }
    
    
     

    Now that you have the structure of the CustomStrandsCatalogCategoryMapper class, you can create your own customization of the Strands catalog feed customization.

  3. Customize the GetItemCategory method as described in one of the following examples:

    1. Using an SKU department ID as the category field in the Strands catalog feed

      
      
      
       /// <summary>
       /// Retrieves SKUDepartmentID which will be used for categorizing the document in the Strands integration.
       /// </summary>
       /// <param name="catalogItem">Document</param>
       /// <returns>Category field</returns>
       public string GetItemCategory(TreeNode catalogItem)
       {
           SKUInfo skuInfo = SKUInfoProvider.GetSKUInfo(catalogItem.NodeSKUID);
           if (skuInfo != null)
           {
               return skuInfo.SKUDepartmentID.ToString(CultureInfo.InvariantCulture);
           }
           throw new Exception("[CustomStrandsCategoryCatalogMapper.GetItemCategory]: SKUInfo was not found for specified TreeNode.");
       }
      
      
       
    2. Using the path to the document as the category field in the Strands catalog feed

      
      
      
       /// <summary>
       /// Retrieves the path to the document, excluding the document's name. The path will be used for categorizing the document in the Strands integration.
       /// </summary>
       /// <param name="catalogItem">Document</param>
       /// <returns>Category field</returns>
       public string GetItemCategory(TreeNode catalogItem)
       {
           string docName = catalogItem.DocumentName;
           string docNamePath = catalogItem.DocumentNamePath;
      
           return docNamePath.Substring(0, docNamePath.Length - docName.Length);
       }
      
      
       
  4. Once you have customized the GetItemCategory method, Save the class file, build your solution, and view your Strands catalog feed. You should see the system categorizing products in the feed according to the new customization.

    1. Note that you can view your Strands catalog feed at http://www.yoursite.com/CMSModules/StrandsRecommender/CMSPages/StrandsCatalogFeed.ashx.
    2. The same categorization is now used in the Strands recommendations web part in the Category recommendation type.

Further customization

You can create any implementation of the IStrandsCatalogCategoryMapper interface and register it in the system using the ObjectFactory class’ SetDefaultObjectTypeTo method.