# Conditions

For each rule you need to provide one or more `conditions` as an array of condition objects.

Conditions determine when a rule's [actions](https://docs.commercelayer.io/rules-engine/actions) are triggered by defining the criteria that must be met for the rule to be applied. They can check for specific values, quantities, or any other attributes of the involved resources and their relationships.

{% hint style="info" %}
Multiple conditions are evaluated according to an `AND` logic (the rule matches if **all** the conditions are met). You can override this default behavior and force the rule to be evaluated according to an `OR` logic (the rule matches if **any** of the conditions are met) by specifying the `conditions_logic` attribute accordingly at the [rule](https://docs.commercelayer.io/rules-engine/rules) level.
{% endhint %}

{% hint style="warning" %}
For performance reasons, the maximum number of conditions within a rules payload is **50**.
{% endhint %}

For each condition you must define at least the involved field and the matcher to be used to compare that field's value against the desired one (if any). Additional parameters can be also specified:

<table><thead><tr><th width="174">Key</th><th width="117">Type<select multiple><option value="kAr4fZJWSc88" label="Integer" color="blue"></option><option value="KRIM7EmMgSbZ" label="Boolean" color="blue"></option><option value="MNwvBNty1Qi7" label="String" color="blue"></option><option value="B6mlBfTvkH1Y" label="Array" color="blue"></option><option value="DisLwSvQctgy" label="Object" color="blue"></option></select></th><th width="100" data-type="checkbox">Required</th><th width="198">Description</th><th>Example</th></tr></thead><tbody><tr><td><strong><code>field</code></strong></td><td><span data-option="MNwvBNty1Qi7">String</span></td><td>true</td><td>The resource's field on which to evaluate the condition (expressed in dot notation). Must be an attribute, cannot be a resource.</td><td><code>"order.line_items.tags.name"</code></td></tr><tr><td><strong><code>matcher</code></strong></td><td><span data-option="MNwvBNty1Qi7">String</span></td><td>true</td><td>The matcher to be used against the field and value (check the <a href="matchers">list of available matchers</a>).</td><td><code>"eq"</code></td></tr><tr><td><strong><code>value</code></strong></td><td><span data-option="KRIM7EmMgSbZ">Boolean, </span><span data-option="kAr4fZJWSc88">Integer, </span><span data-option="MNwvBNty1Qi7">String, </span><span data-option="B6mlBfTvkH1Y">Array, </span><span data-option="DisLwSvQctgy">Object</span></td><td>true</td><td>The value to be compared with the field value according to the <code>matcher</code> (required for <a href="../matchers#value-required">some matchers</a>, unavailable for <a href="../matchers#value-not-required">some others</a>). <a href="conditions/dynamic-values">Dynamic values</a> are also allowed.</td><td><p><code>true</code><br><code>2000</code></p><p><code>"summer-sale"</code></p><p><code>[ "2018-01-01T00:00:00+02:00", "2018-03-31T23:59:00+02:00" ]</code><br><code>{ "in_or": [ "men", "women" ], "not_in_and": [ "sales", "vip" ] }</code></p></td></tr><tr><td><strong><code>scope</code></strong></td><td><span data-option="MNwvBNty1Qi7">String</span></td><td>false</td><td>The policy to determine if the condition is a match. Can be one of <code>any</code> or <code>all</code>, default is <code>all</code> (more information <a href="conditions/scope">here</a>).</td><td><code>"any"</code></td></tr><tr><td><strong><code>group</code></strong></td><td><span data-option="MNwvBNty1Qi7">String</span></td><td>false</td><td>A label to identify the matches of the condition (if not specified a random UUID will be automatically generated and added by the <a href="../readme#core-api-integration">Core API integration</a>).</td><td><code>"discountable-items"</code></td></tr><tr><td><strong><code>aggregations</code></strong></td><td><span data-option="B6mlBfTvkH1Y">Array</span></td><td>false</td><td>Additional requirements on the aggregated matches of the conditions.</td><td>Learn more <a href="conditions/aggregations">here</a>.</td></tr><tr><td><strong><code>nested</code></strong></td><td><span data-option="DisLwSvQctgy">Object</span></td><td>false</td><td>Additional conditions to be met by the matches of the parent condition.</td><td>Learn more <a href="conditions/nested">here</a>.</td></tr></tbody></table>

{% hint style="warning" %}
Referring to the [Core API integration](https://docs.commercelayer.io/rules-engine/readme#core-api-integration), a condition `field` must be an **attribute** — i.e. the last leaf of the relationship tree using the dot notation (e.g. it can be `order.line_items.sku.code` but it cannot be `order.line_items.skus` or just `order`). Some [virtual relationships](https://docs.commercelayer.io/rules-engine/core-api-integration/virtual-relationships) related to the currently issued JWT token are also enabled.
{% endhint %}

## Example

### Group

Assuming no `conditions_logic` is specified at the [rule](https://docs.commercelayer.io/rules-engine/rules) level, the following couple of conditions check if an order is tagged as `dropship` *and* contains at least a line item whose SKU code starts with `TSHIRT`. The matching line items are grouped as `tshirts` so that the related actions (that will be triggered only if both conditions are satisfied) can be applied only to the line items that matches the second condition:

<pre class="language-json"><code class="lang-json"><strong>"conditions": [
</strong>  {
    "field": "order.tags.name",
    "matcher": "eq",
    "value": "dropship"
  },
  {
    "field": "order.line_items.sku.code",
    "matcher": "start_with",
    "value": "TSHIRT",
<strong>    "group": "tshirts"
</strong>  }
]
</code></pre>
