Re: Discount coupon value
I forgot to write it, but discount coupon is fixed at $8.
Then, if you look at total when displaying with no tax ($89.17) for what is considered good, it should be $89.18 so that numbers in the column above add correctly. In Excel sheet calculation for coupon value and tax are done without rounding which gives a total of $89.174 rounded at the end to $89.17.
Which result should be displayed in ZC, I am not sure. I would probably go for the mathematically more precise one of $89.17. It then equals the total when displaying tax.
To come back to coupons calculation, I will try to locate code that gives this weird 8.73 number in ot_coupon.php file.
Re: Discount coupon value
I got it fixed.
There were 3 problems:
1- Getting rid of all zen_round function calls fixed or at list minimized penny loss problem
2- Code to display coupon value was adding the tax difference when displaying prices with tax and doing nothing when displaying prices without tax. It should be the opposite, just display coupon value when prices with tax are displayed and remove tax difference when prices without tax are displayed.
Lines 597 and 598:
PHP Code:
if (DISPLAY_PRICE_WITH_TAX == 'true' && $coupon_details['coupon_type'] == 'F') {
$od_amount['total'] += $od_amount['tax'];
are replaced with this:
PHP Code:
if (DISPLAY_PRICE_WITH_TAX == 'false' && $coupon_details['coupon_type'] == 'F') {
$od_amount['total'] -= $od_amount['tax'];
3- Tax calculation after discount uses a ratio between discount and total of taxable products. It worked ok when displaying prices with tax, but when displaying prices without tax, it was using total without tax, which is wrong. It should always be total including taxes.
To fix this, line 50:
PHP Code:
$orderAmountTotal = (string)$orderTotalDetails['orderTotal']; // coupon is applied against value of only qualifying/restricted products in cart
was replaced by this:
PHP Code:
$orderAmountTotal = (DISPLAY_PRICE_WITH_TAX == 'true') ? (string)$orderTotalDetails['orderTotal'] : (string)($orderTotalDetails['orderTotal'] + $orderTotalDetails['orderTax']); // coupon is applied against value of only qualifying/restricted products in cart
Now everything looks good, but some testing is still needed with other settings.
2 Attachment(s)
Re: Discount coupon value
Re: Discount coupon value
For Discount coupon by percentage, a modification was necessary too.
Line 545 was changed from:
PHP Code:
$od_amount['total'] = zen_round($orderAmountTotal * ($coupon_details['coupon_amount'] / 100), $currencyDecimalPlaces);
To this:
PHP Code:
$od_amount['total'] = (DISPLAY_PRICE_WITH_TAX == 'true') ? $orderAmountTotal * ($coupon_details['coupon_amount'] / 100) : ($orderTotalDetails['orderTotal'] + $orderTotalDetails['orderTax'] - $orderTotalDetails['shippingTax']) * ($coupon_details['coupon_amount'] / 100);
And lines 597-598 from:
PHP Code:
if (DISPLAY_PRICE_WITH_TAX == 'true' && $coupon_details['coupon_type'] == 'F') {
$od_amount['total'] += $od_amount['tax'];
To this:
PHP Code:
if (DISPLAY_PRICE_WITH_TAX == 'false' && ($coupon_details['coupon_type'] == 'F' || $coupon_details['coupon_type'] == 'P')) {
$od_amount['total'] -= $od_amount['tax'];
Re: Discount coupon value
Thanks for this, @pilou2! In going through the other rounding errors, I had a feeling that these calculation issues would arise in ot_coupon as well.
Since that's going to be a fairly major change to that module, I'm suggesting that we defer these corrections to Zen Cart 2.0.1 so that we can get some testing time in on that and all the other rounding-related changes.
Re: Discount coupon value
For tracking purposes, I've opened this GitHub issue: https://github.com/zencart/zencart/issues/6339
Re: Discount coupon value
Quote:
Originally Posted by
lat9
Thanks for this, @pilou2! In going through the other rounding errors, I had a feeling that these calculation issues would arise in ot_coupon as well.
Since that's going to be a fairly major change to that module, I'm suggesting that we defer these corrections to Zen Cart 2.0.1 so that we can get some testing time in on that and all the other rounding-related changes.
Yes, we need time... Although I have made good progresses. Different discount options are now all working: fixed, %, free shipping and combination with tax displayed or not.
I need to put this code on GitHub so you can easily look at it.
Re: Discount coupon value
Quote:
Originally Posted by
pilou2
Yes, we need time... Although I have made good progresses. Different discount options are now all working: fixed, %, free shipping and combination with tax displayed or not.
I need to put this code on GitHub so you can easily look at it.
Sounds great, I/we truly appreciate your help on this.
Re: Discount coupon value
I set a new branch on GitHub:
https://www.zen-cart.com/showthread....t-coupon-value
I am not sure how to give you right to comment, modify it...