5.02

Cart Promo Rules

Describe promo rules: totals framework, conditions (EAV attributes), actions (percent, fixed, Buy X get Y), coupons, shipping, and tax interactions.

Why This Matters: Cart promo rules (shopping cart price rules) apply discounts via the totals framework. Understanding conditions (EAV attributes), actions (percent, fixed, Buy X get Y), coupons, shipping, and tax interactions is essential for reliable promotions.

Cart Promo Rules Overview

mindmap root((Promo Rules)) Totals Framework SalesRule/etc/sales.xml Applied during collectTotals Conditions Boolean logic EAV attributes Used in Promo Rule Conditions flag Actions Percent discount Fixed amount discount Fixed amount whole cart Buy X get Y free Coupons Coupon codes Auto/specific Shipping Apply to shipping or not Free shipping Carrier decides logic Taxes Tax calculation settings Discount subtlety

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.

Magento/SalesRule/etc/sales.xml

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).
Key: To use a product attribute in promo rule conditions, set "Used in Promo Rule Conditions" to Yes in the attribute config.

Further reading: StackExchange: Shopping Cart Rule Based on Custom Attribute

Actions

Four action types define how discounts apply:

  1. Percent of product price discount
    • Subtracts a percentage from each qualifying item's price.
    • Example: Discount Amount = 10 → 10% off each item.
  2. Fixed amount discount
    • Subtracts a fixed amount from each qualifying item's price.
    • Example: Discount Amount = 10 → $10 off each item.
  3. 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").
  4. 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.
Important: It's the shipping method (carrier) that decides how to apply discounts or free shipping when calculating rates. Always account for promo rules in custom shipping methods.

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).