Discounts
Thor has two discount systems that run at different points in the commerce flow:
- product discounts change product and variant prices before they are added to a cart
- cart discounts change a cart after line items, shipping, customer, currency, store, and discount codes are known
Use product discounts for catalog pricing such as sale prices, campaign prices, customer-group prices, or channel-specific price reductions. Use cart discounts for checkout promotions such as basket discounts, line-item promotions, and discount-code campaigns.
Product discounts
Product discounts are catalog-level discounts. They target product variant prices with the product predicate language, then Thor stores the resulting discounted price on matching prices.
A product discount has:
- a
predicatethat selects eligible product, variant, price, channel, country, and customer-group contexts - a
value, either relative or absolute - optional
validFromandvalidUntildates - a non-negative
priority
Lower priority numbers win. If a price already has a discount from a higher-priority product discount, a lower-priority discount will not replace it. Equal priority can replace the existing discounted price when discounts are refreshed.
Product discounts affect Storefront price fields such as variant price and discounted price. They are not discount codes and customers do not add them to a cart.
Cart discounts
Cart discounts are checkout-level discounts. They are evaluated whenever Thor recalculates the cart.
A cart discount has:
- a
predicatewritten in the cart predicate language - a
target, such as cart total or line items - a
value, either relative or absolute - optional
validFromandvalidUntildates - a non-negative
priority - optional discount-code requirement
Thor builds discount candidates from the current cart context. The context includes customer data, customer groups, discount codes, store, price channel, currency, addresses, subtotal, total, and line items. If the predicate does not match that context, the discount is ignored.
Discount codes
Discount codes are separate resources that can be assigned to cart discounts.
A cart discount can be configured with requiresDiscountCode. When enabled, the discount only becomes a candidate if the cart has a matching, valid code. Codes support:
- one or more case-insensitive code strings
- optional validity dates
- optional maximum applications
- optional maximum applications per customer
Storefront clients add and remove codes with cart mutations. Adding a code does not guarantee that a discount applies. The code must resolve to a discount-code resource, pass usage limits, match a cart discount, and survive the best-deal policy.
If a code is present but cannot apply, Thor keeps the code on the cart with an error such as no match, max applications reached, max applications per customer reached, or excluded by discount policy.
Discount groups
Cart discount groups control how multiple cart discounts are considered together.
A group has a name, a stacking mode, and an ordered list of cart discounts. The stacking mode decides how discounts inside the group combine:
SERIAL: discounts are applied one after anotherPARALLEL: discounts are each calculated from the original price
During cart recalculation, Thor compares every ungrouped discount and every discount group, then applies the option that produces the best total discount for the cart. This means groups are not just folders in the Admin API. A group is a promotion bundle that competes with other candidate discounts.
For grouped cart-total discounts, group order is respected through the group’s sort order. For grouped line-item discounts, Thor currently groups candidates per line item before calculating the best result.
Evaluation order
The practical model is:
- product discounts are resolved into product prices before cart discount evaluation
- cart discount codes are validated against existence, dates, and usage limits
- Thor builds cart discount candidates from valid cart context and matching predicates
- candidates are sorted by priority or group sort order
- ungrouped discounts and groups compete under the best-deal policy
- the winning applications are written back to the cart, line items, and totals
Use priorities to express precedence within a discount type. Use groups when several cart discounts should be evaluated as one promotion strategy.