Conditions

How to set a rule's conditions and what are the required and optional parameters to set

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

Conditions determine when a rule's 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.

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 level.

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:

Key
Type
Required
Description
Example

field

String

The resource's field on which to evaluate the condition (expressed in dot notation). Must be an attribute, cannot be a resource.

"order.line_items.tags.name"

matcher

String

The matcher to be used against the field and value (check the list of available matchers).

"eq"

value

BooleanIntegerStringArrayObject

The value to be compared with the field value according to the matcher (required for some matchers, unavailable for some others). Dynamic values are also allowed.

true 2000

"summer-sale"

[ "2018-01-01T00:00:00+02:00", "2018-03-31T23:59:00+02:00" ] { "in_or": [ "men", "women" ], "not_in_and": [ "sales", "vip" ] }

scope

String

The policy to determine if the condition is a match. Can be one of any or all, default is all (more information here).

"any"

group

String

A label to identify the matches of the condition (if not specified a random UUID will be automatically generated and added by the Core API integration).

"discountable-items"

aggregations

Array

Additional requirements on the aggregated matches of the conditions.

Learn more here.

nested

Object

Additional conditions to be met by the matches of the parent condition.

Learn more here.

Example

Assuming no conditions_logic is specified at the rule 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:

"conditions": [
  {
    "field": "order.tags.name",
    "matcher": "eq",
    "value": "dropship"
  },
  {
    "field": "order.line_items.sku.code",
    "matcher": "start_with",
    "value": "TSHIRT",
    "group": "tshirts"
  }
]

Last updated