Need to create rules based on bundles?
Learn more
LogoLogo
APIsChangelog
  • Getting started
  • Rules
  • Conditions
    • Scope
    • Aggregations
    • Nested
    • Dynamic values
  • Actions
    • Types
      • Percentage
      • Fixed amount
      • Fixed price
      • Buy X pay Y
      • Every X discount Y
    • Bundle
      • Balanced
      • Every
    • Aggregation
    • Limit
  • Matchers
  • Operators
  • Check and validation
  • Core API integration
    • Order rules
    • Price rules
    • Virtual relationships
  • Resources
    • Promotions
    • Price lists
  • Use cases
    • Promotions
      • Discount line items based on item's price
      • Get a discount when paying by credit card
      • Discount an order based on promo item and total number of items
      • Offer a specific shipping method for free in a specific country
      • Discount items with large stock availability
      • Discount all the SKU in an order based on the shipping country
      • Discount all the SKU in an order based on the customer email domain
    • Price lists
      • Discount all prices greater than or equal to a specific value
      • Discount specific SKUs for new clients
      • Change strike-through price based on customer email domain
On this page
  1. Actions

Aggregation

How to aggregate the targets of an action

PreviousEveryNextLimit

Last updated 3 months ago

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 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 ).

The allowed aggregation field values are limited by the related action's selector value, meaning that the former must be within the scope defined by the latter (i.e. an attribute of one of the entities specified in the action's selector). For example, if the action's selector is order.line_items you can aggregate over order.line_items.quantity but not over order.customer.total_orders_count because the customer entity is not within the scope set by the selector.

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
  }
]
operator
same structure