Order rules

How the Rules Engine integration with Commerce Layer Core API promotions resource works behind the scenes

When you create a flex promotion filling up the related rules object you're basically setting up order rules, meaning that the Core API integration will check your rules against the payload of an order. For performance reasons, it is a lightweight version of the full order payload, containing only the attributes and relationships needed to evaluate the rule conditions and apply the related actions based on the values specified in the rule keys (e.g. fields, selectors, etc.).

The resulting promotion (i.e. the rule actions) will be applied to all the orders that satisfy the rule conditions.

Example

The following order rule offers free shipping and a 10% discount on the line items associated with an SKU if the email of the customer belongs to a specified domain:

{
  "rules": [
    {
      "name": "Get 10% off item cost plus free shipping for company customers",
      "conditions": [
        {
          "field": "order.customer_email",
          "matcher": "matches",
          "value": ".*@mybrand.com"
        }
      ],
      "actions": [
        {
          "type": "percentage",
          "selector": "order.line_items.sku",
          "value": "0.1"
        },
        {
          "type": "percentage",
          "selector": "order.line_items.shipment",
          "value": "1"
        }
      ]
    }
  ]
}

Last updated