Dynamic values
How to leverage dynamic values for a rule's conditions.
The value
key of a condition can be dynamic. This is extremely useful when the value to be compared with the field
value isn't known in advance or is based on the value of another field.
To leverage dynamic values for a rule's conditions you need to use the double curly brackets notation {{<reference_field>}}
where <reference_field>
is the resource's field (expressed in dot notation) that will be used as a variable to calculate the value. Some basic operators that can be applied to the reference field are also provided (as shown in the examples below):
min
The smallest of the reference field values is used as the condition's value.
"{{min(order.line_items.shipment.available_shipping_methods.price_amount_cents)}}"
max
The biggest of the reference field values is used as the condition's value.
"{{max(order.line_items.compare_at_amount_cents)}}"
avg
The average of the reference field values is used as the condition's value.
"{{avg(order.line_items.sku.inventory.levels.quantity))}}"
The reference field type must be consistent with the matcher used against the field and value. Given the currently available functions, if you want to add one of the operators above, the reference field type must be numeric.
Examples
Direct dynamic value
The following condition uses a dynamic value to check if an order's line items have the same unit amount and compare-at amount (i.e. the actual selling price is equal to the full price displayed to the customer with a strikethrough — that is to say, the items is not in sale):
Dynamic value with operator
The following condition uses a dynamic value with the min
operator to target the shipment line items associated with the cheapest shipping method among the ones available for an order's shipments:
Last updated