# Order rules

When you [create a flex promotion](https://docs.commercelayer.io/rules-engine/resources/promotions) 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](https://app.gitbook.com/s/RWJeylueWkzLadK710XZ/orders/object), containing only the attributes and relationships needed to evaluate the rule [conditions](https://docs.commercelayer.io/rules-engine/conditions) and apply the related [actions](https://docs.commercelayer.io/rules-engine/actions) based on the values specified in the rule keys (e.g. fields, selectors, etc.).

{% hint style="info" %}
The resulting promotion (i.e. the rule actions) will be applied to all the orders that satisfy the rule conditions.
{% endhint %}

{% hint style="success" %}
The structure, constraints, and data types for the order rules JSON dataset are described in the public [Order Rules JSON schema](https://core.commercelayer.io/api/public/schemas/order_rules). 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.
{% endhint %}

## Example

{% tabs %}
{% tab title="Rules" %}
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:

<pre class="language-json"><code class="lang-json">{
  "rules": [
    {
      "name": "Get 10% off item cost plus free shipping for company customers",
      "conditions": [
        {
<strong>          "field": "order.customer_email",
</strong>          "matcher": "matches",
          "value": ".*@mybrand.com"
        }
      ],
      "actions": [
        {
          "type": "percentage",
<strong>          "selector": "order.line_items.sku",
</strong>          "value": "0.1"
        },
        {
          "type": "percentage",
<strong>          "selector": "order.line_items.shipment",
</strong>          "value": "1"
        }
      ]
    }
  ]
}
</code></pre>

{% endtab %}

{% tab title="Order" %}
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`

<pre class="language-json"><code class="lang-json">{
  "order": {
    "id": "oXkhYLlzgE",
<strong>    "customer_email": "john@mybrand.com",
</strong><strong>    "line_items": [
</strong>      {
        "id": "dKdhYLlzgE",
        "quantity": 1,
<strong>        "sku": { "id": "dKfhgdlzgE" }
</strong>      },
      {
        "id": "eKfhYFkztQ",
        "quantity": 2,
<strong>        "sku": { "id": "sDfhYFkcfR" }
</strong>      },
      {
        "id": "kKffYAkzdW",
        "quantity": 2,
<strong>        "sku": { "id": "sWfhYDccwQ" }
</strong>      },
      {
        "id": "adfSYwAzar",
        "quantity": 1,
<strong>        "shipment": { "id": "dwFhYDGtwE" }
</strong>      }
    ]
  }

</code></pre>

{% endtab %}
{% endtabs %}
