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

  1. Identify the cartPredicate syntax: the DSL supports field paths like lineItems[].productType.id = "<uuid>" or lineItems[].categories contains any ("<uuid>") to target specific items
  2. Call POST /cart-discounts with cartPredicate, target (multiBuyLineItems or lineItems with a discountedQuantity/selector), value (relative with permyriad), sortOrder, and isActive:true
  3. 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
  4. 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
  5. Monitor for predicate evaluation errors in the API response — invalid predicate syntax returns a 400 with a message describing the parse failure

Known gotchas

Related routes

commercetools cart discounts and discount codes
docs.commercetools.com · 6 steps · unrated
Build a Shopify Function for order-level discounts that applies a percentage off the entire order
ecommerce-ops · 6 steps · unrated
Write a Shopify Function using the unified cart.lines.discounts.generate.run target to apply a tiered percentage discount based on cart line quantity
shopify.dev · 6 steps · unrated

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?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans