Aggregation

How to aggregate the targets of an action

The selected items on which an action should apply can be aggregated based on another field's values. Those values are aggregated using a specified operator and the results of the aggregation is compared against a provided value using the aggregation's matcher to add additional restrictions and define the overall aggregated items on which to apply the action.

Unlike the condition's aggregations key, which is an array of aggregation objects, an action's aggregation key is a single object (with the same structure).

Example

The following action applies a 30% discount to the order's line items labeled as discountable-items by the related conditions only if the sum of their total amounts doesn't exceed 4500 cents.

"actions": [
  {
    "type": "percentage",
    "selector": "order.line_items",
    "groups": [ "discountable-items" ],
    "aggregation": {
      "field": "order.line_items.total_amount_cents",
      "operator": "sum",
      "matcher": "lteq",
      "value": 4500
    },
    "value": 0.3
  }
]

Last updated