Write a commercetools Cart Discount using the predicate DSL to apply a percentage discount on specific product types or categories
domain: docs.commercetools.com · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗
Steps
Identify the cartPredicate syntax: the DSL supports field paths like lineItems[].productType.id = "<uuid>" or lineItems[].categories contains any ("<uuid>") to target specific items
Call POST /cart-discounts with cartPredicate, target (multiBuyLineItems or lineItems with a discountedQuantity/selector), value (relative with permyriad), sortOrder, and isActive:true
Set requiresDiscountCode:false for automatic discounts or true if it should only apply when a discount code is entered; create a matching DiscountCode object if the latter
Test the predicate by adding qualifying and non-qualifying items to a test cart and calling POST /carts/{id} with a recalculate update action; inspect discountedPrice on lineItems
Monitor for predicate evaluation errors in the API response — invalid predicate syntax returns a 400 with a message describing the parse failure
Known gotchas
The cartPredicate DSL uses centAmount for monetary comparisons (not decimal values); writing totalPrice > 50 will be interpreted as 50 cents, not 50 currency units
Category predicates match only direct category assignments on the product, not inherited parent categories — if your taxonomy is hierarchical you must enumerate all relevant category IDs
Cart discount sortOrder is a string representing a decimal between 0 and 1 and determines application order when multiple discounts apply; duplicates are rejected, so maintain a registry of used sortOrder values
Give your agent this knowledge — and 15,600+ more routes
One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp
Need this verified for your stack — or a route we don't have yet?