Discount Coupon Tax issue
We came across the following issues when applying Discount Coupons:
- Fixed amount discount coupons apply more discount than configured eg. £0.20 coupon applied £0.23 discount instead
- Percentage discount coupons calculate against tax-inclusive prices regardless of tax settings eg. 10% discount on £1.00 + VAT (displayed as £1.20) showed as £0.12 instead of £0.10
Cause
When DISPLAY_PRICE_WITH_TAX is set to true, the coupon module incorrectly handles tax in two ways:
- Base calculation issue: Percentage discounts are calculated against tax-inclusive amounts even when MODULE_ORDER_TOTAL_COUPON_INC_TAX is set to false
- Final amount issue: Tax is incorrectly added to fixed amount coupons even when MODULE_ORDER_TOTAL_COUPON_INC_TAX is set to false
Solution
Two changes are required in includes/modules/order_total/ot_coupon.php
Fix 1: Base Calculation (Line 683)
From:
Code:
if (DISPLAY_PRICE_WITH_TAX !== 'true') {
To:
Code:
if (DISPLAY_PRICE_WITH_TAX !== 'true' || $this->include_tax !== 'true') {
Why needed
This ensures that tax is removed from the base order total when calculating discounts if the coupon module is configured to exclude tax, regardless of how prices are displayed in the store.
Fix 2: Final Amount (Line 597)
From:
Code:
if (DISPLAY_PRICE_WITH_TAX == 'true' && $coupon_details['coupon_type'] == 'F') {
To:
Code:
if (DISPLAY_PRICE_WITH_TAX == 'true' && $coupon_details['coupon_type'] == 'F' && $this->include_tax == 'true') {
Why needed
This prevents tax from being added to the final discount amount for fixed amount coupons when the coupon module is configured to exclude tax. Both fixes ensure the coupon module properly respects the MODULE_ORDER_TOTAL_COUPON_INC_TAX setting throughout all calculations.
Note:
This issue was initially noticed in Zen Cart 2.1.0 but may exist in other versions
Re: Discount Coupon Tax issue
Thanks for the report and details! I've created a GitHub PR containing those changes: https://github.com/zencart/zencart/pull/7121
Re: Discount Coupon Tax issue
@Ryk, please see comments made in the GitHub pull request; there are apparently some issues with the suggested changes.
Re: Discount Coupon Tax issue
... you are moving into a land of both shadow and substance of things and ideas, you have just crossed over into the TWILIGHT ZONE!!!
A little bit of humor that I think describes the situation well enough... unfortunately.
A pity I can't add the music.