Results 1 to 10 of 24

Hybrid View

  1. #1
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    130
    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:	153 
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
    130
    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
    130
    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
    130
    Plugin Contributions
    5

    Default Re: Discount coupon value

    Here are the results:
    Click image for larger version. 

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

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

  5. #5
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    130
    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,542
    Plugin Contributions
    89

    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
    Jan 2004
    Posts
    66,374
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Discount coupon value

    Quote Originally Posted by pilou2 View Post
    Here are the results:
    Click image for larger version. 

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

Name:	Discount_wt.png 
Views:	34 
Size:	6.8 KB 
ID:	20531
    I acknowledge that you've made many updates to proposed coding changes since posting these screenshots, so I'm posting to ask whether the latest code still works as shown in these images?
    ... because in the US (tax-included-pricing is 'false'), if a person redeems a coupon worth $8.00, they'll want to see that coupon being worth $8.00 not $7.28 in the subtotals.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

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

    Default Re: Discount coupon value

    Quote Originally Posted by DrByte View Post
    I acknowledge that you've made many updates to proposed coding changes since posting these screenshots, so I'm posting to ask whether the latest code still works as shown in these images?
    ... because in the US (tax-included-pricing is 'false'), if a person redeems a coupon worth $8.00, they'll want to see that coupon being worth $8.00 not $7.28 in the subtotals.
    Well, yes and no... In countries I know, there is always a sale tax to apply and when a shop gives you a discount it is always on final prices (tax included). It seems that in US, even at consumer level, tax excluded is the base. In ZC the option to recalculate tax allows both, hopefully. Problem is that in original code 'Credit Note' option was used for tax included discount (I think it was depending on the module), but credit note are in fact an accounting tool (negative invoice) used between company that trade tax excluded and do their adjustments (discounts) tax excluded too.
    Because of this and my own experience of discounts, I interpreted the 'Credit Note' option as tax excluded discount and 'Standard' option as tax included.
    Actual code follows this interpretation which might be opposite of original code.
    Shop owners have to be careful how they set these options or it might end up like you said with an invoice different that what was said.
    If you display prices without tax, then discount re-calculate tax should be set to 'Credit Note' with new code. If prices are displayed tax included, 'standard' option would be the best choice. Although in some case, like trade between professionals, you can have a mix of these.

 

 

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