Magento Tax Calculation with Coupon Code

Magento Tax Calculation with Coupon Code

September 29, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Tax Calculation with Coupon Code

Magento Tax Calculation With Coupon Code: A Comprehensive Guide

Hello developers! Today, we’re going to tackle an issue many of you might face while working on Magento projects—tax calculation when a coupon code is applied. If you’re seeing incorrect tax amounts and basket totals after applying a discount, don’t worry; I’ll guide you through the solution.

Understanding the Issue: Tax Calculation With Coupon Code

In your case, the issue lies in how Magento handles tax calculation when a fixed amount coupon (10€) is applied to the basket total. The problem isn’t with the tax configuration itself (which looks fine), but with how Magento applies the discount.

Before we dive into the solution, let me briefly explain what’s happening:

  1. You have configured your tax rates correctly.
  2. The product prices are including tax.
  3. When a fixed amount coupon is applied, Magento subtracts it from the total price before calculating tax.

How to Resolve the Tax Calculation Issue

To resolve this issue, we need to modify how Magento processes the discount and recalculate the tax accordingly. Here’s a step-by-step solution:

  1. Disable automatic calculation of tax

    By default, Magento calculates tax automatically when a coupon is applied. To disable this feature temporarily, go to your admin panel:

    • System > Configuration
    • Sales Tax > Tax Calculation Settings
    • Set “Calculate tax for zero total” to “Yes”
    • Save the configuration
  2. Create an observer

    We’ll create an event observer that will be triggered when a coupon is applied. This observer will recalculate the tax based on the discounted total.

    Here’s a simple observer example:

class DiscountTaxObserver implements ObserverInterface
{
    public function execute(ObserverEventArgs $args)
    {
        if ($args->getEvent()->getName() === 'sales_apply_discount_after') {
            /** @var \Magento\Sales\Model\Order $order */
            $order = $args->getOrder();
            $quote = $order->getQuote();

            // Recalculate tax based on discounted total
            $quote->collectTotals()->save();
        }
    }
}

Don’t forget to register this observer in your module’s etc/events.xml file:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/config.xsd">
    <event name="sales_apply_discount_after">
        <observer name="discount_tax_observer" instance="Vendor\ModuleName\Model\DiscountTaxObserver"/>
    </event>
</config>
  1. Clear cache and reindex

    After implementing the observer, clear your Magento cache and reindex:

    • System > Cache Management
    • Select all
    • Flush Magento Cache

    Then, run the following commands in the terminal (replace m2 with your Magento version):

php m2 dev:cache:clean
php m2 indexer:reindex

Verifying the Solution

After making these changes and refreshing the checkout page, you should see that the tax calculation is now correct. The discount is applied to the total price before the tax is calculated.

Remember, this solution assumes that your Magento installation is up-to-date and that you have the necessary permissions to make these changes.

Conclusion: Tax Calculation in Magento

In this blog post, we’ve discussed a common issue with tax calculation when using fixed amount coupons in Magento. By understanding how Magento processes discounts and implementing an observer, we can resolve this issue and ensure accurate tax amounts even when coupon codes are applied.

I hope this guide has been helpful! If you’re looking for more in-depth tutorials on Magento development or need assistance with any other Laravel-related topics, feel free to explore our blog at https://laravelcompany.com/blog.

Happy coding!

Catalog Admin Configuration Pricing

Our network