Magento: Mysterious Discount Calculation Error
If you’re an e-commerce store owner using Magento, you might have come across some oddities when it comes to discount calculations during checkout. A recent query from Magento Community Forum highlights this issue:

In the above image, notice how Magento subtracts the discount amount (692.98) from the subtotal (6929.82), but ends up with a result of 6321.94 instead of the expected value of 6236.84.
Let’s dive into this mystery and uncover what might be causing such strange behavior in your Magento store.
Unraveling the Mystery
1. Configuring Discounts Correctly
The first place to look is your discount configuration settings under Promotions > Cart Price Rules. Ensure that you have selected Fixed as the Discount Amount Type and Percent of item price as the Discount Calculation Setting.

2. Checking Tax Settings
Next, navigate to Stores > Taxes. Check your tax rates under Tax Zones and Rates. Ensure that you have correctly configured the tax rate of 14% for the relevant customer groups.

3. Inspecting Core Files
If the above settings are correct, there might be an issue with your Magento core files or a third-party extension causing interference.
Review your app/code/core/Mage/Sales/etc/config.xml file and ensure that it hasn’t been tampered with or overridden by any custom code:
<config>
<modules>
<!-- ... -->
<Mage_Sales active="true">
<codePool>core</codePool>
<depends>
<Mage_Tax />
</depends>
</Mage_Sales>
</modules>
</config>
4. Disabling Custom Themes and Extensions
To rule out any custom theme or extension interference, temporarily disable all your active themes and extensions. Restore the default Magento theme (Luma for version 2.x) and re-run the checkout process.
If the issue persists even after these steps, it might be a bug in your specific Magento version. In such cases, consider upgrading to the latest stable release or reaching out to the official Magento Support.
Conclusion
In most cases, mysterious discount calculation errors like this are due to misconfigured settings or customizations overriding core Magento functionality.
Double-check your configuration settings and ensure that your tax rates and discount rules are set up correctly. If the issue persists after verifying these areas, consider seeking professional help from an experienced Magento developer or contacting Magento’s official support channels for further assistance.
Remember, keeping your Magento version up-to-date is crucial to avoid such bugs and security vulnerabilities in the long run. Regularly update your store to benefit from performance improvements, new features, and critical bug fixes.
For more insights into Magento development best practices and common troubleshooting techniques, feel free to explore our comprehensive guides on Laravel Company.