This page is available in English. Switch to English

Skip to content
Open Source

Stop Discount Stacking in Magento 2 — An Extensible, Open-Source Approach

Guard/Strategy-Architektur zur Vermeidung von Rabattstapelung in Magento

You set a special price on a product: €100 down to €75, a 25% discount. A customer applies a 30% off coupon. Magento stacks them. The customer pays €52.50, a 47.5% total discount. That’s not what you intended.

This is Magento’s default behaviour. Cart price rules apply on top of special prices, catalog price rules, and tier pricing. For most merchants this means either accepting margin erosion they didn’t plan for, manually excluding every discounted product from every coupon rule, or hoping customers don’t notice. None of these are real solutions.

What the module does

PixelPerfect Discount Exclusion intercepts Magento’s discount calculation via an around plugin on Validator::process() and applies configurable logic to prevent unwanted stacking.

The key design decision: it’s not a hardcoded blocker. It’s a pluggable architecture with guards and strategies that you can extend for your own business rules.

The structure looks like this:

Sales Rule Processing
├── Guards: Should we even check for exclusions?
│   ├── CouponOnly — skip automatic rules, only check coupon-based
│   ├── Ampromo — don't block free gift rules
│   └── ZeroPrice — skip zero-price items
├── Strategies: Is this product already discounted?
│   ├── SpecialPriceStrategy — active special price detected
│   └── CatalogRuleStrategy — catalog price rule active
└── Decision
    ├── Excluded → block the coupon discount
    └── Not excluded → proceed normally

The bypass mode

Sometimes you want a coupon to work on discounted products, but only if it gives a better deal than the existing discount. Each rule has a "Bypass Discount Exclusion" toggle that enables max-discount logic.

Using the example above: product regular price €100, special price €75 (25% off), coupon is 30% off.

Without bypass: coupon is blocked because the product is already discounted.

With bypass: max(25%, 30%) = 30%, so the target price is €70. An additional €5 discount is applied. The customer gets the better deal, but the discounts never stack.

Messages

The module doesn’t silently block discounts. It tells the customer what happened:

"The coupon could not be applied to [Product Name] because it already has a special price."

"[Product Name] already has a 25% discount. Your 30% coupon gives a better deal — we applied the difference."

Messages appear on the cart page and are configurable per store view.

Extending it

If you need a custom guard, for example to skip exclusion logic for a specific customer group:

class VipCustomerGuard implements StrategyEligibilityGuardInterface
{
    public function canProcess($product, $item, $rule): bool
    {
        $customerGroupId = $item->getQuote()->getCustomerGroupId();
        return $customerGroupId !== self::VIP_GROUP_ID;
    }
}

Or a custom strategy to check for manufacturer promotions stored in a custom attribute:

class ManufacturerPromoStrategy implements DiscountExclusionStrategyInterface
{
    public function shouldExcludeFromDiscount($product, $item): bool
    {
        return (bool) $product->getData('manufacturer_promo_active');
    }
}

Both registered via di.xml, no core modifications.

Installation

composer require pixelperfectat/magento2-module-discount-exclusion
bin/magento module:enable PixelPerfect_DiscountExclusion
bin/magento setup:upgrade

Compatible with PHP 8.3+ and Magento 2.4.x. The module also serves as the foundation for the Checkout Discount Display module, which handles the customer-facing side of the same problem.

If you’ve ever had a client call because a coupon gave too much discount, that’s exactly the conversation this module exists because of. GitHub repository here. Questions or custom discount logic: get in touch.

Discounts Extensions Magento Open Source