Zen Cart Version 1.3.9f but I've checked and the errant code has not changed in 1.3.9h.
There is an error in the order totals when a discount coupon is applied.
This becomes apparent when the ot_coupon is configured in admin as follows:
Include Shipping: false
Include Tax: false
Recalculate Tax: Standard
The site is configured to show prices with tax.
Here is an example of how the order totals are calculated:
Item in cart value = £20
Shipping Cost = £5
Discount coupon = 25%
VAT (UK sales tax) = 20%
On checkout the order totals are displayed as follows:
Sub-Total: £20.00
Shipping: £5.00
Discount: £4.79
VAT: £3.33
Total: £20.21
These figures are clearly wrong.
The discount should be 25% of the Sub-Total i.e. not applied to the shipping = .25 x £20 = £5.00
The Total should therefore be £20.00(original value) + £5.00(Shipping) - £5.00(Coupon discount) = £20.00
VAT at 20% on a VAT inclusive price of £20.00 = £20.00 - (£20.00/1.2) = £3.33
The problem lies in includes/modules/order_total/ot_coupon.php on line 459. I have included this line the preceding 2 lines below
Code:
if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost'];
if ($this->include_shipping != 'true') $order_total_tax -= $order->info['shipping_tax'];
if ($this->include_tax != 'true') $order_total -= $order->info['tax'];
Basically what these lines do are as follows:
Line 457
If shipping is not included then apply the discount to the order total value minus the shipping costs
ie £25.00 - £5.00 = £20.00
Line 458
Again, if shipping is not included then reduce the total tax component by the value of the tax included in the shipping cost
ie £4.16(tax component of £25) - £0.83(tax component of £5) = £3.33
Line 459
Finally, if tax is not included further reduce the order total value by the total tax
ie £20.00(from line 457) - £4.16(the total tax on the non discounted order value) = £15.84
The discount to be applied is therefore 0.25 x £15.84 = £3.96.
This discount is applied to the VAT exclusive selling price of the items in the cart
ie £20.83 - £3.96 = £16.87
The VAT value is correctly calculated for the discounted value plus the shipping (presumably by ot_tax.php) and added
ie £16.87 + £3.33 = £20.20
This is the order total value displayed as above - there is a £0.01 rounding error.
The order total before applying the discount coupon is £20.00 + £5.00 shipping = £25.00
The new order total as calculated above is £20.21 (rounding!).
The discount is the difference ie £4.79
This is all as displayed at checkout.
And unfortunately utterly wrong!
If we change line 459 to the following:
[code]
if ($this->include_tax != 'true') $order_total -= $order_total_tax;
[code]
We effectively reduce the order total value we use for our calculations not by the total VAT but by only the VAT applicable to the discounted items (ie excluding shipping) see line 458.
Doing this the new order total value becomes:
£20.00(from line 457) - £3.33(from line 458) = £16.67
The discount to be applied is therefore 0.25 x £16.67 = £4.16
This discount is applied to the VAT exclusive selling price of the items in the cart
ie £20.83 - £4.16 = £16.67
The VAT value is correctly calculated for the discounted value plus the shipping (presumably by ot_tax.php) and added
ie £16.67 + £3.33 = £20.00
This is the correct result!
And at checkout we see
Sub-Total: £20.00
Shipping: £5.00
Discount: £5.00
VAT: £3.33
Total: £20.00
Which is the desired (and correct) result.
Bookmarks