Cart Promo Rules
Describe promo rules: totals framework, conditions (EAV attributes), actions (percent, fixed, Buy X get Y), coupons, shipping, and tax interactions.
Cart Promo Rules Overview
Promo Rules Architecture
Promo rules (shopping cart price rules) are applied via the Totals framework, registered in Magento/SalesRule/etc/sales.xml. They follow the same engine as Catalog Price Rules but add coupon code support.
Core Elements: Conditions & Actions
Conditions
Conditions define a boolean function that determines if a rule applies to a cart. Conditions support:
- Cart subtotal, quantity, weight, etc.
- EAV attributes of products in the cart (e.g., category, custom attributes).
- Customer segments (when enabled).
Further reading: StackExchange: Shopping Cart Rule Based on Custom Attribute
Actions
Four action types define how discounts apply:
- Percent of product price discount
- Subtracts a percentage from each qualifying item's price.
- Example: Discount Amount = 10 → 10% off each item.
- Fixed amount discount
- Subtracts a fixed amount from each qualifying item's price.
- Example: Discount Amount = 10 → $10 off each item.
- Fixed amount discount for whole cart
- Subtracts a fixed amount from the cart total (usually subtotal).
- Example: Discount Amount = 10 → $10 off cart subtotal.
- Optional: Apply to shipping as well ("Apply to Shipping Amount").
- Buy X get Y free
- Defines a quantity X the customer must purchase to receive quantity Y for free.
- Discount Amount represents Y (free quantity).
Coupon Codes
Unlike catalog price rules, cart promo rules can require coupon codes. Coupons can be:
- Specific: Defined codes (e.g., "SUMMER20").
- Auto-generated: Magento generates codes with a pattern/prefix.
- No coupon: Rule auto-applies when conditions match.
Discounts & Shipping
A promo rule can be configured to:
- Discount shipping: Apply to Shipping Amount option.
- Free shipping: Special action that sets shipping cost to zero.
Discounts & Taxes
Tax calculation settings affect discount application. Subtleties include:
- Before/after discount: Taxes can be calculated before or after discount is applied.
- Including/excluding tax: Configuration determines if discounts apply to tax-inclusive or tax-exclusive amounts.
See admin: Stores → Configuration → Sales → Tax → Calculation Settings.
Rule Similarity to Catalog Price Rules
Both promo rules and catalog price rules use the same Rule engine for conditions. Main difference: cart promo rules support coupons and apply at cart/checkout scope, while catalog rules apply at product listing scope.
Further Reading
Exam Tips
- Application: Promo rules are applied via the Totals framework (see
Magento/SalesRule/etc/sales.xml). - Conditions: Can use EAV product attributes if "Used in Promo Rule Conditions" is Yes.
- Actions: 4 types—percent, fixed per item, fixed whole cart, Buy X get Y.
- Coupons: Specific, auto-generated, or none (auto-apply).
- Shipping: Carrier/shipping method must handle discount/free shipping logic.
- Taxes: Discount interaction depends on tax calculation settings (before/after, incl/excl).