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

WhiteSpace
Form Feed (U+000C)
Line Feed (U+000A)
Carriage Return (U+000D)
Horizontal Tab (U+0009)
Space (U+0020)

1.2Identifiers

RawIdentifier
/[_A-Za-z][_A-Za-z0-9]*/
EscapedRawIdentifier
/`[-_A-Za-z0-9]+`/

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"
BooleanValue
true
false
Integer
/-?([1-9][0-9]+|[0-9])/
Digits
/[0-9]+/
Exponent
/[eE][+-]?[0-9]+/
LineTerminator
New Line (U+000A)
Carriage Return (U+000D)New Line (U+000A)
EscapedUnicode
/[0-9A-Fa-f]{4}/
SourceCharacter
/[\u0009\u000A\u000D\u0020-\uFFFF]/

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 > or is 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 or is 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 of true = true
  • lineItemExists(...) instead of lineItemExists(...) = true
  • lineItemsTotal(true) > "10.00 USD" instead of lineItemsTotal(true = true) > "10.00 USD"

§Index

  1. AndExpression
  2. BasicComparison
  3. BooleanValue
  4. CollectionComparison
  5. ConditionalExpression
  6. Digits
  7. DiscountPredicateExpression
  8. EscapedCharacter
  9. EscapedRawIdentifier
  10. EscapedUnicode
  11. Exponent
  12. FieldExpression
  13. Fraction
  14. FunctionApplicationExpression
  15. FunctionArgument
  16. FunctionArguments
  17. Identifier
  18. Integer
  19. LineTerminator
  20. ListOfValues
  21. NegateExpression
  22. NotEquals
  23. NumberValue
  24. OrExpression
  25. OrderedComparison
  26. PrimitiveValue
  27. PrimitiveValues
  28. RawIdentifier
  29. ShortCircuitExpression
  30. SourceCharacter
  31. StringCharacter
  32. StringValue
  33. TargetExpression
  34. WhiteSpace
  1. 1Language Grammar
    1. 1.1White Space
    2. 1.2Identifiers
    3. 1.3Primitive Values
    4. 1.4Discount Predicate
      1. 1.4.1Logical Operators
      2. 1.4.2Conditional Expressions
      3. 1.4.3Function Expressions
      4. 1.4.4Short Circuit Expression
  2. §Index