Commercetools examples

This page includes common use cases usually seen with commercetools catalog integrations.

Product selection

You can access product selections at data.__productSelections, and filter the desired selection mode.

(
  {
    "metadata": [
      {
        "key": "productSelectionInclusions",
        "value": data.__productSelections[mode="Individual"].key
      },
      {
        "key": "productSelectionExclusions",
        "value": data.__productSelections[mode="IndividualExclusion"].key
      }
    ]
  }
)

Discount

Discounts are available in variations, under prices.__discounted.

(
  {
    "metadata": [
      {
        "key": "discountNames",
        "value": $distinct(data.variant.prices.__discounted.discount.name)
      }
    ]
  }
)

Review rating statistics

Review rating statistics are available at the product level, under data.__reviewRatingStatistics.

(
  {
    "metadata": [
      {
        "key": "avgerageRating",
        "value": data.__reviewRatingStatistics.averageRating
      },
      {
        "key": "reviewsCount",
        "value": data.__reviewRatingStatistics.count
      }
    ]
  }
)

Price

Prices are available per variation, under prices.

(
  {
    "metadata": [
      {
        "key": "price",
        "value": data.variant.prices[0].value.centAmount / 100
      }
    ]
  }
)

Custom fields

You can access custom fields in both product and variation levels, under attributesRaw. Generally, you'll want to filter the custom attribute per key, and potentially parse the value.

(
  $getItemAttributeValue := function($name) {
    data.masterData.current.masterVariant.attributesRaw[name = $name].value
  };

  {
    "metadata": [
      { 
        "key": "color",
        "value": $getItemAttributeValue("color")
      }
    ]
  }
)