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. Core API integration

Order rules

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

PreviousCheck and validationNextPrice rules

Last updated 3 months ago

When you 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 , containing only the attributes and relationships needed to evaluate the rule and apply the related 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.

The structure, constraints, and data types for the order rules JSON dataset are described in the public . Feel free to use it to implement validation scripts for your rules, automatically generate code, or just better understand how the Rules Engine works behind the scenes.

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"
        }
      ]
    }
  ]
}

The lightweight version of the order payload the rule is checked against by the Core API integration will contain only the strictly necessary information to evaluate the rule matching:

  • The order's customer_email

  • The order's line items of type skus and shipments

{
  "order": {
    "id": "oXkhYLlzgE",
    "customer_email": "john@mybrand.com",
    "line_items": [
      {
        "id": "dKdhYLlzgE",
        "quantity": 1,
        "sku": { "id": "dKfhgdlzgE" }
      },
      {
        "id": "eKfhYFkztQ",
        "quantity": 2,
        "sku": { "id": "sDfhYFkcfR" }
      },
      {
        "id": "kKffYAkzdW",
        "quantity": 2,
        "sku": { "id": "sWfhYDccwQ" }
      },
      {
        "id": "adfSYwAzar",
        "quantity": 1,
        "shipment": { "id": "dwFhYDGtwE" }
      }
    ]
  }
create a flex promotion
conditions
actions
Order Rules JSON schema
full order payload