Merchant rules are a strict, versioned JSON DSL. The host evaluates them against a cart; there is no merchant-authored JavaScript.
Document shape
{
"rules": [
{
"id": "welcome-10",
"name": "Welcome 10%",
"enabled": true,
"when": { "currency_code": "usd", "subtotal_min": 5000 },
"then": {
"type": "order_discount_percent",
"percent": 10,
"code": "WELCOME10"
}
}
]
}Rule ids match ^[a-z][a-z0-9_-]{0,63}$. Unknown fields are rejected, so a
typo cannot silently change pricing.
Conditions (when)
| Field | Meaning |
|---|---|
currency_code |
Cart currency must match. |
subtotal_min / subtotal_max |
Subtotal bounds in minor units. |
item_count_min / item_count_max |
Item quantity bounds. |
product_ids |
Cart must contain one of these products. |
variant_ids |
Cart must contain one of these variants. |
All declared conditions must match.
Actions (then)
| Type | Fields |
|---|---|
order_discount_percent |
percent, optional code |
order_discount_amount |
amount_minor, optional code |
line_discount_percent |
percent, optional code, product_ids, variant_ids |
block_checkout |
reason |
Evaluation
- Rules run in document order.
- Each discount sees the remaining base after previous adjustments.
- Merchant discounts apply before plugin adjustments.
- The host validates targets, currency, discountable lines, and amount bounds, then recomputes totals.
- Rules that cannot apply are reported in
dropped, not thrown during a cart read. - A malformed stored rule set fails checkout closed.
Versioning and limits
- One active rule set per store; saving creates a draft version.
- Activating a version archives the previous one.
- At most 50 rules and 100 adjustments.
- The serialized document is limited to 32 KiB.
API
| Method | Path | Purpose |
|---|---|---|
GET / POST |
/api/merchant-rules |
List versions / create a draft |
POST |
/api/merchant-rules/:id/activate |
Activate a version |
POST |
/api/merchant-rules/simulate |
Evaluate against a cart |