Page 1 of 3 123 LastLast
Results 1 to 10 of 22
  1. #1
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    123
    Plugin Contributions
    5

    Default Discount coupon value

    On ZC v2.0.0-rc2, discount coupons are displayed /calculated wrong values in checkout pages.
    There is a unique tax class with rate of 10%.
    There are two items in cart, one at $48.34 and the other at $35.00 gross price.
    Flat rate shipping ($5) is used as shipping method and is set to same tax class as items (10%).
    'ot_coupon' settings are default.

    Coupon value is wrong when displaying prices with tax (orange color), which makes although tax and total wrong. But tax and total calculations appear to be good.
    In table below, 'ZC' column is what is displayed in ZC v2.0.0-rc2, 'Good' column is what I think it should be and just for information and to identify lost penny, I included a 'no rounding' column. There is actually a penny loss in tax calculation when displaying prices with tax.
    Click image for larger version. 

Name:	Discount_coupon.png 
Views:	137 
Size:	20.2 KB 
ID:	20529
    My understanding of discount coupons is that the discount should be applied to final total ($97.17 including tax) to get the new total and that tax should be re-calculate to fit this new total.
    Last edited by pilou2; 19 Mar 2024 at 06:14 PM.

  2. #2
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    123
    Plugin Contributions
    5

    Default 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.

  3. #3
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    123
    Plugin Contributions
    5

    Default 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.

  4. #4
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    123
    Plugin Contributions
    5

    Default Re: Discount coupon value

    Here are the results:
    Click image for larger version. 

Name:	Discount_wot.png 
Views:	24 
Size:	7.0 KB 
ID:	20530Click image for larger version. 

Name:	Discount_wt.png 
Views:	27 
Size:	6.8 KB 
ID:	20531

  5. #5
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    123
    Plugin Contributions
    5

    Default 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']; 

  6. #6
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,498
    Plugin Contributions
    88

    Default 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.

  7. #7
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,498
    Plugin Contributions
    88

    Default Re: Discount coupon value

    For tracking purposes, I've opened this GitHub issue: https://github.com/zencart/zencart/issues/6339

  8. #8
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    123
    Plugin Contributions
    5

    Default Re: Discount coupon value

    Quote Originally Posted by lat9 View Post
    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.

  9. #9
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,498
    Plugin Contributions
    88

    Default Re: Discount coupon value

    Quote Originally Posted by pilou2 View Post
    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.

  10. #10
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    123
    Plugin Contributions
    5

    Default 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...

 

 
Page 1 of 3 123 LastLast

Similar Threads

  1. v155 Discount Coupon - Minimum Order Value Excluding Tax
    By allmart in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 12
    Last Post: 20 Jul 2020, 06:38 PM
  2. Replies: 6
    Last Post: 19 Jun 2011, 07:06 AM
  3. Replies: 18
    Last Post: 12 Mar 2010, 06:37 PM
  4. Ideas/Suggestions for Discount Coupon - How to give a credit and a discount
    By vegascoug in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 0
    Last Post: 15 Nov 2007, 05:40 PM
  5. Coupon welcome message showing discount when coupon is expired
    By tracyselena in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 4
    Last Post: 26 Jan 2007, 06:32 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR