Introduction
Conditions play an important role in setting up rules and actions in the Rule Engine. They use operators, variables, constants, and functions to help decide checkout options based on factors such as weight, cart price, and destination.
Rules consist of one or more conditions connected to actions, which can influence fields, addons, or delivery options, determining the outcomes when the conditions are satisfied. The Rule Engine interface makes it easy to set up conditions and actions.
For more information on common use cases, take a look at our article Using the Rule Engine, which offers a step-by-step guide to creating basic conditions.
This article will focus on the more advanced aspects of conditions:
Advanced view in the Rule Engine
In the Rule engine, you have the option to switch to Advanced mode. This contains a single text field and enables you to write conditions manually for better control.
Examples:
vip = true
Custom text "vip" equals true
cart_price < 100
Cart price is less than 100
to_country != "SE"
Country is not equal to Sweden
to_postal_code < "10000" and to_country = "SE" and to_postal_code > "20000"
Receiver post code is less than 10000 and receiver country is equal to Sweden and post code is less than 20000
List of valid operators
Writing conditions require the use of operators:
| Operator |
Explanation |
|---|---|
| + | Addition |
| - | Subtraction |
| * | Multiplication |
| / | Division |
| = | Equal |
| != | Not equal |
| > | Greater than |
| >= | Greater than or equal |
| < | Less than |
| <= | Less than or equal |
| |, or | Or |
| &, and | And |
| ! | Not |
| ?, in | In (used for condition lists and arrays and returns true if at least one input is in the condition list) |
| all | All (used for condition lists and arrays and returns true if all input is in the condition list) |
| from | From (used for conditions lists) |
| % | Modulo |
| ><, between x;y | Between x and y (inclusive) (shorter way of writing x > y and x < z) |
Expressions
Expressions work similarly to Conditions but serve a different purpose. While Conditions return a boolean (true/false) to decide if an action should happen, Expressions are used to dynamically set values in fields like prices or messages. Expressions must be written inside curly braces, "{}".
For example, in a price field, an expression might use a custom variable from the request. Or, to show a delivery message, you could write:
"Will be delivered on {nextWorkingDayReceiver()}"
Here, {nextWorkingDayReceiver()} is the expression. The curly braces {} tell the system to evaluate the content inside. If the function returns "Monday", the final message becomes:
"Will be delivered on Monday"
Note: If an expression returns a boolean (like a condition), it will display "true" or "false" as text, which may not be what you want.
Some functions are only available in expressions, not in conditions, because they depend on knowing which shipping option is being used, something not available at the checkout level.
| Name | Result type |
|---|---|
| carrierEtaFromDate | Date |
| carrierEtaToDate or carrierEtaDate | Date |
| carrierEtaFromDateTime | DateTime |
| carrierEtaToDateTime or carrierEtaDateTime | DateTime |
| carrierEtaFromDay | String |
| carrierEtaToDay or carrierEtaDay | String |
| carrierEtaInterval | String |