Set Up a Compliant Index Pipeline

This shows how to set up a compliant index pipeline for commerce tools.

Custom JavaScript stage to add ID

A repeatable, unique, valid ID must be set for each document so that the integration can store the links between products for future deletion/re-indexing. To add this, a custom JS stage must be added to your index pipeline.

  1. Go to the Index Pipelines configuration.

  2. Open the index pipeline you plan to use with the integration.

  3. Insert a new JavaScript stage at the top of your index pipeline.

  4. Give it a name like Set DocID.

    Name js stage

  5. In the condition field, enter true.

  6. In the Script Body field, enter:

    function (doc, ctx) {
     // Set doc ID
     var productID = doc.getFirstFieldValue("fusion_doc_id");
     doc.setId(productID);
    
     return doc;
    }

    JS stage script

  7. Save the pipeline.

Custom JavaScript stage for product deletions

  1. Go to the Index Pipelines configuration.

  2. Open the index pipeline you plan to use with the integration.

  3. Insert a new JavaScript stage near the start of your index pipeline.

  4. Give it a name like JS Handle Deletes.

    Product deletions

  5. In the condition field, enter:

    doc.getFirstField("action") != null && doc.getFirstFieldValue("action") == "DELETE";

    Deletions condition field

  6. In the Script Body field, enter:

    function (doc, ctx, collection,solrServer) {
     var actionField = "action";
     if (doc.getFirstFieldValue(actionField) != null &&  doc.getFirstFieldValue(actionField) == "DELETE") {
       solrServer.deleteById(doc.getId());
       solrServer.commit();
     }
     return null;
    }

    Condition script body

  7. Save the pipeline.