Price rules

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

When you create or patch a price list filling up the related rules object you're basically setting up price rules, meaning that the Core API integration will check your rules against the payload of a price. For performance reasons, it is a lightweight version of the full price 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.).

Adding a price rule to a price list will result in applying the discounts due to the rule actions to all the price list's prices that satisfy the rule conditions.

Example

The following rule offers a 20% discount on the prices of some promotional products (identified by a prefix in their SKU code) for the price lists associated with specific markets:

{
  "rules": [
    {
      "name": "20% discount off promo products in EU and AU markets",
      "conditions": [
        {
          "field": "price.sku.code",
          "matcher": "start_with",
          "value": "PROMO"
        },
        {
          "field": "price.jwt_markets.name",
          "matcher": "is_in",
          "value": ["Europe", "Australia"]
        }
      ],
      "actions": [
        {
          "type": "percentage",
          "selector": "price",
          "value": "0.2"
        }
      ]
    }
  ]
}

Last updated