Management Tooling - Expressions
Expressions are a set of conditions that evaluate to true or false. The payload passed into the Processor API can be evaluated against these to determine if they satisfy the expression.
For example, you may have a Segments
property on a customer and you may want to setup a discount to only apply for customers in the VIP segment.
In this case you can create an expression for Segments Contains VIP
and setup a discount to use the expression on a condition.
There are two types of expressions:
- Eligibility - these are expressions that are not related to line items
- Line Item - these use line item properties
Expressions can be used in two ways:
- Global expressions that are given a name and can be reused by other expressions or discounts
- Inline expressions that are created where they are needed (e.g. the eligibility expression on a discount condition)
Global Expressions
Global expressions are managed in the Expressions section of the tooling:
The navigation on the left can be used to switch between Eligibility and Line Item expressions.
Expressions use the same publishing model as discounts. See the Publishing Model guide for an overview and the Discounts guide for how they work in the tooling.
To create a global expression click the "Add expression" button. You are taken to the expression builder page:
Inline Expressions
Inline expressions have the same options as global ones, but don't require a name. You can choose to reference a global expression or just create an inline expression. If you want to reuse the expression in other places, create a global one.
Building Expressions
An expression is made up of clauses and groups of clauses. All expressions have a top-level group.
Click the "Add clause" button to see the types of clauses that can be added:
Below are some details on the types of clauses:
- Property - a predicate using a single property and value. E.g. currency code is USD.
- List - a predicate using a single property and multiple values. E.g. currency code is USD or GBP or EUR.
- Expression - reference another expression that must evaluate to true.
- Property comparison - a predicate that does a comparison of two properties. E.g. Line Item Price is equal to Line Item Discounted Price.
Note. the properties available for building clauses are defined in the Properties page of the Admin section. See Properties for more details.
Property
Below is an example of a property clause:
List
Below is an example of a property list clause:
Expression
Below is an example of an expression reference clause:
Property Comparison
Below is an example of a property comparison clause for a line item expression:
Editing Clauses
Use the 3 dots icon on the right to edit or remove an existing clause:
Groups
Groups can be used to build more complex expressions and control how clauses interact with each other.
On a group you can choose if all the clauses in the group need to match (i.e. clauses are combined with an AND
) or if any clause needs to match (i.e. clauses are combined with an OR
)
Below is an example using a nested group. The clauses in the root group all have to evaluate to true, but either of the clauses in the nested group need to evaluate to true.
So a line item with a Product Type
of Shirt
as well as either On Sale
or Price Marked Down
will satisfy the expression.