The production-ready Medusa DTC Starter is outRead the announcement
C

Cart rules

Medusa v2 plugin: cart & per-product quantity rules scoped by customer group, sales channel, product, variant, collection or category.

npm install @xross-dev/medusa-cart-rules
Category
Built by
Version
0.1.1
Last updated
1 week ago
Monthly downloads
Loading downloads

@xross-dev/medusa-cart-rules

Medusa v2 plugin. Blocks add-to-cart, quantity increase and checkout when a quantity rule is violated.

Rules

Meaning
Total items ≤ limit. Scope = whole cart; other scopes = combined items matching the scope (e.g. "max 4 items from collection X").
Per product ≤ limit (per variant when scope = ). Scope = every product; // = matching products.

Audience: everyone (+ optional guests), or one customer group. Also: sales channel, active window (/), priority, custom message ().

Resolution

  • Per-product: variant > product > collection/category > global (first tier with a matching rule wins).
  • Same scope target: a customer-group rule overrides the "everyone" rule (VIP 50 beats global 20).
  • Several matching group rules: (lowest, default) or (highest).
  • Cart-level and product-level rules are checked independently; all must pass.
  • Decreasing a quantity is always allowed. Add/update only block for products they touch; checks the whole cart.

Install

Dev loop: in the plugin, in the app.

API

Admin (auth required): , , , .

Store (publishable key): or

Use to cap the quantity stepper.

Blocked requests return HTTP 400 .

Custom rule types

Call it from a loader or any file loaded at boot. The engine () is pure (no I/O) and unit-tested: .

Notes

  • Workflow hooks used: , , → .
  • Scope/group/channel IDs are plain strings (no module links), validated on create/update.
  • Admin page: Cart Rules in the sidebar (rules CRUD + blocked-attempts log), built with .