Copy existing getProducts Pipeline

The pipeline shopgate.catalog.getProducts.v1 is taking care of fetching all products from a category, search term, or a filter. It’s used for the search, category view and the product detail page.

To start with modifying the pipeline we need to copy the existing one. After running the sgconnect backend start all existing pipelines are downloaded to the pipelines folder.

So we just need to copy the pipeline from pipelines/shopgate.catalog.getProducts.v1.json to /extensions/loyaltyPoints/pipelines/shopgate.catalog.getProducts.v1.json.

Add a New Step and Pipeline Output

When we look a bit closer at the steps of the pipeline we see that the first steps are fetching all requested products. The output is an array of products and all information for pagination.

So we can add our step as the very last step of the pipeline. To add our loyaltyPoints property to the product array we need to add products as an input and an output of our step.

Add the code below to the end of the steps array.

{
  "type": "extension",
  "id": "@myAwesomeOrganization/loyaltyPoints",
  "path": "@myAwesomeOrganization/loyaltyPoints/addLoyaltyPoints.js",
  "input": [
    {
      "id": "100",
      "key": "products"
    }
  ],
  "output": [
    {
      "id": "100",
      "key": "products"
    }
  ]
}

After adding the new step, the shopgate.catalog.getProducts.v1.json will look like this:

shopgate.catalog.getProducts.v1.json
After Loyalty Point Step is Added
{
  "version": "1",
  "pipeline": {
    "id": "shopgate.catalog.getProducts.v1",
    "input": [
      {
        "id": "1",
        "key": "categoryId",
        "optional": true
      },
      {
        "id": "2",
        "key": "searchPhrase",
        "optional": true
      },
      {
        "id": "3",
        "key": "filters",
        "optional": true
      },
      {
        "id": "4",
        "key": "offset",
        "optional": true
      },
      {
        "id": "5",
        "key": "limit",
        "optional": true
      },
      {
        "id": "6",
        "key": "sort",
        "optional": true
      },
      {
        "id": "7",
        "key": "productIds",
        "optional": true
      },
      {
        "id": "8",
        "key": "skipHighlightLoading",
        "optional": true
      },
      {
        "id": "9",
        "key": "skipLiveshoppingLoading",
        "optional": true
      },
      {
        "id": "15",
        "key": "showInactive",
        "optional": true
      },
      {
        "id": "750",
        "key": "sgxsMeta"
      },
      {
        "id": "751",
        "key": "characteristics",
        "optional": true
      }
    ],
    "steps": [
      {
        "id": "@shopgate/products",
        "path": "@shopgate/products/products/getProducts.js",
        "type": "extension",
        "input": [
          {
            "id": "1",
            "key": "categoryId",
            "optional": true
          },
          {
            "id": "2",
            "key": "searchPhrase",
            "optional": true
          },
          {
            "id": "3",
            "key": "filters",
            "optional": true
          },
          {
            "id": "4",
            "key": "offset",
            "optional": true
          },
          {
            "id": "5",
            "key": "limit",
            "optional": true
          },
          {
            "id": "6",
            "key": "sort",
            "optional": true
          },
          {
            "id": "7",
            "key": "productIds",
            "optional": true
          },
          {
            "id": "15",
            "key": "showInactive",
            "optional": true
          },
          {
            "id": "751",
            "key": "characteristics",
            "optional": true
          }
        ],
        "output": [
          {
            "id": "10",
            "key": "service"
          },
          {
            "id": "11",
            "key": "version"
          },
          {
            "id": "12",
            "key": "path"
          },
          {
            "id": "13",
            "key": "method"
          },
          {
            "id": "14",
            "key": "query"
          }
        ]
      },
      {
        "id": "@shopgate/bigapi",
        "path": "@shopgate/bigapi/big-api/getBigApiResult.js",
        "type": "extension",
        "input": [
          {
            "id": "10",
            "key": "service"
          },
          {
            "id": "11",
            "key": "version"
          },
          {
            "id": "12",
            "key": "path"
          },
          {
            "id": "13",
            "key": "method"
          },
          {
            "id": "14",
            "key": "query"
          }
        ],
        "output": [
          {
            "id": "100",
            "key": "collection"
          },
          {
            "id": "101",
            "key": "meta"
          }
        ]
      },
      {
        "id": "@shopgate/products",
        "path": "@shopgate/products/products/updateAvailableText.js",
        "type": "extension",
        "input": [
          {
            "id": "100",
            "key": "products"
          }
        ],
        "output": [
          {
            "id": "100",
            "key": "products"
          }
        ]
      },
      {
        "id": "@shopgate/products",
        "path": "@shopgate/products/products/convertProducts.js",
        "type": "extension",
        "input": [
          {
            "id": "100",
            "key": "products"
          },
          {
            "id": "101",
            "key": "meta"
          }
        ],
        "output": [
          {
            "id": "100",
            "key": "products"
          },
          {
            "id": "301",
            "key": "productsLength"
          },
          {
            "id": "1000",
            "key": "totalProductCount"
          }
        ]
      },
      {
        "id": "@shopgate/products",
        "path": "@shopgate/products/products/addPrices.js",
        "type": "extension",
        "input": [
          {
            "id": "750",
            "key": "sgxsMeta"
          },
          {
            "id": "100",
            "key": "products"
          }
        ],
        "output": [
          {
            "id": "100",
            "key": "products"
          }
        ]
      },
      {
        "else": {
          "id": "addHighlights_int",
          "type": "pipeline",
          "input": [
            {
              "id": "100",
              "key": "products"
            }
          ],
          "output": [
            {
              "id": "100",
              "key": "products"
            }
          ]
        },
        "then": {
          "type": "staticValue",
          "input": [
            {
              "id": "100",
              "key": "products"
            }
          ],
          "output": [
            {
              "id": "100",
              "key": "products"
            }
          ],
          "values": [
            {
              "key": "products",
              "passthrough": "products"
            }
          ]
        },
        "type": "conditional",
        "input": [
          {
            "id": "8",
            "key": "skipHighlightLoading",
            "optional": true
          },
          {
            "id": "301",
            "key": "productsLength"
          }
        ],
        "expression": {
          "any": [
            {
              "ok": [
                {
                  "name": "skipHighlightLoading",
                  "type": "input"
                }
              ]
            },
            {
              "notok": [
                {
                  "name": "productsLength",
                  "type": "input"
                }
              ]
            }
          ]
        }
      },
      {
        "else": {
          "id": "addLiveshoppings_int",
          "type": "pipeline",
          "input": [
            {
              "id": "100",
              "key": "products"
            }
          ],
          "output": [
            {
              "id": "100",
              "key": "products"
            }
          ]
        },
        "then": {
          "type": "staticValue",
          "input": [
            {
              "id": "100",
              "key": "products"
            }
          ],
          "output": [
            {
              "id": "100",
              "key": "products"
            }
          ],
          "values": [
            {
              "key": "products",
              "passthrough": "products"
            }
          ]
        },
        "type": "conditional",
        "input": [
          {
            "id": "9",
            "key": "skipLiveshoppingLoading",
            "optional": true
          },
          {
            "id": "301",
            "key": "productsLength"
          }
        ],
        "expression": {
          "any": [
            {
              "ok": [
                {
                  "name": "skipLiveshoppingLoading",
                  "type": "input"
                }
              ]
            },
            {
              "notok": [
                {
                  "name": "productsLength",
                  "type": "input"
                }
              ]
            }
          ]
        }
      },
      {
        "type": "extension",
        "id": "@myAwesomeOrganization/loyaltyPoints",
        "path": "@myAwesomeOrganization/loyaltyPoints/addLoyaltyPoints.js",
        "input": [
          {
            "id": "100",
            "key": "products"
          }
        ],
        "output": [
          {
            "id": "100",
            "key": "products"
          }
        ]
      }
    ],
    "output": [
      {
        "id": "1000",
        "key": "totalProductCount"
      },
      {
        "id": "100",
        "key": "products"
      }
    ],
    "public": true
  }
}