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": {
"productSelectionInclusions": data.__productSelections[mode="Individual"].key,
"productSelectionExclusions": data.__productSelections[mode="IndividualExclusion"].key
}
}Discount
Discounts are available in variations, under prices.__discounted.
{
"metadata": {
"discountNames": $distinct(data.prices.__discounted.discount.name)
}
}Review rating statistics
Review rating statistics are available at the product level, under data.__reviewRatingStatistics.
{
"metadata": {
"averageRating": data.__reviewRatingStatistics.averageRating,
"reviewsCount": data.__reviewRatingStatistics.count
}
}Price
Prices are available per variation, under prices.
{
"metadata": {
"price": data.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": {
"color": $getItemAttributeValue("color")
}
}
)Updated about 1 month ago