Docs
Dashboard

Predicate language

Last updated View as Markdown

Predicate language

A predicate is a boolean condition used by a commerce rule. It answers whether a cart, line item, or price record matches that rule. It does not query resources or replace the rule’s other configuration.

Select the right context

RulePredicate reads
Cart discount, shipping method or rate, payment gatewayCart context
Cart discount line-item targetOne line item
Product discountProduct-price context

A search clause such as tag:lighting is not a predicate. A full-cart expression using line_items.any(...) is not a line-item target expression. The target already represents one line.

Syntax

Use ==, !=, >, >=, <, and <= for comparisons. Use &&, ||, and ! for boolean logic, with parentheses to make grouping explicit. Supported contexts use snake_case fields, string literals, numbers, booleans, and null. Collections support the methods documented by their context, including Contains, any, and count.

Cart conditions
Code in text

Compare money in minor units and pair thresholds with currency. Guard nullable values before reading nested fields. Copy resource IDs from Thor and use the expected casing for codes and strings. Write true explicitly when a rule intentionally matches every eligible context.

Test intent, not only syntax

Start with one condition and verify it through the supported Admin validation or save operation. Then test a matching case, a non-matching case, and the boundary value. For cart rules, include anonymous customers and missing addresses. For product-price rules, include prices with and without optional dimensions.

A matching predicate only establishes eligibility. Scheduling, discount targets, priority, and combination settings can still change the result. Use Create a discount campaign for a complete workflow.