Commercetools Discount Predicate Spec
1Language Grammar
This document describes the predicate language syntax for cart and product discounts in the commercetools platform.
All language keywords are case insensitive.
1.1White Space
1.2Identifiers
1.3Primitive Values
These language syntax rules define basic partitive values like string or number.
An example of number literal
Example № 1123.045e-10
And this is an example or string literal
Example № 2"An example \u00F0\u009F\u0091\u008D string\n"
" | \ | / | b | f | n | r | t |
1.4Discount Predicate
1.4.1Logical Operators
Basic logical operators. An example:
Example № 3[some expression] and ([some expression] or not [some expression])
1.4.2Conditional Expressions
This part of the language syntax defines conditional expressions. In general all conditional expressions consist of 3 parts:
- The left side or the target. The target is a field name, a function application or a constant.
- The operator (like
>
oris defined
). In addition to providing the condition itself, the operator delineates the right side from the left side of the expression. - The right side. The right side defines the value we are comparing against the target. It is a constant or a list of constants. For some operators, like
is empty
oris defined
, the right side expression is absent. If the right side of the expression is absent, the right side is implied as= true
.
Examples:
Example № 4price = "10.00 EUR"
Example № 5attributes.size in ("xxl", "xl")
!= | <> |
1.4.3Function Expressions
Function expressions consist of a function name and a list of arguments. For example:
Example № 6lineItemTotal(sku = "TEST")
In this example, lineItemTotal
is the function name and sku = "TEST"
is the first argument (a nested predicate).
1.4.4Short Circuit Expression
Short circuit expressions allow a simplified variation of the predicates.
Some examples:
true
instead oftrue = true
lineItemExists(...)
instead oflineItemExists(...) = true
lineItemsTotal(true) > "10.00 USD"
instead oflineItemsTotal(true = true) > "10.00 USD"
§Index
- AndExpression
- BasicComparison
- BooleanValue
- CollectionComparison
- ConditionalExpression
- Digits
- DiscountPredicateExpression
- EscapedCharacter
- EscapedRawIdentifier
- EscapedUnicode
- Exponent
- FieldExpression
- Fraction
- FunctionApplicationExpression
- FunctionArgument
- FunctionArguments
- Identifier
- Integer
- LineTerminator
- ListOfValues
- NegateExpression
- NotEquals
- NumberValue
- OrExpression
- OrderedComparison
- PrimitiveValue
- PrimitiveValues
- RawIdentifier
- ShortCircuitExpression
- SourceCharacter
- StringCharacter
- StringValue
- TargetExpression
- WhiteSpace