Adding information from a product to the index for faceting purposes is easy to achieve if the information is already part of the product (sellableitem). In this example we add new fields regarding the related product variants directly to the product and index them using the standard Sitecore methods.

The main advantage of this approach is that you will not need to modify the standard crawlers or create calculated index fields. All the work is handled by the commerce engine making the index processing faster.

Below is a video describing the example and what the final solution looks like. It also shows how to generate the Sitecore templates and add a new facet. The code for the example is also below.

There a couple things to note…

What this example does :-

  1. Adds the pipelines and other scaffolding to enable the storage of the variant search information.
  2. Example code on how to populate the values that will be searched on. For example, Size, Color Style, Price range, percentage off etc.
  3. Shows how to add the new field to the search config on the Sitecore side.
  4. Shows how to add a new facet to the products in Sitecore so the standard SXA components can show the facets filter on the list page.
  5. Show how to index price information for a specific catalog. As selling prices can be different per catalog only the price for a particular catalog are indexed.

What this example does not do :-

  1. Index the variants themselves
  2. Show exactly where you would populate the search fields. This will depend on your individual business case i.e. use a minion or part of your catalog integration.
  3. Index prices for multiple catalogs for the same product. You will need a custom crawler for this.

Watch this before looking at the code…

Step 1 – Create new plugin

  • In the Commerce Engine SDK create a new plugin and reference it from the engine
  • Add the following code to create the pipelines

In folder “Pipelines” create…

In folder “Pipelines\Arguments” create…

In folder named “Pipelines\Blocks” create…

  • Add the following code to be able to execute the code externally via the API

In folder “Commands”…

In folder “Controllers”…

In folder “Components”…

In the root of your project add…

Your solutions should look like this…

productvariantsindex

Step 2 – Run

    1. Go to Postman and run https://{{ServiceHost}}/{{ShopsApi}}/GenerateFacetsCommand
    2. Watch the video for further instructions