Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2004
    Location
    Glasgow, Scotland
    Posts
    251
    Plugin Contributions
    0

    Default Coupon Discount Totals Incorrect

    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.

  2. #2
    Join Date
    Mar 2004
    Location
    Finland
    Posts
    488
    Plugin Contributions
    3

    Default Re: Coupon Discount Totals Incorrect

    This has been the case for as long as I remember with any stock discount modules in ZenCart.

    They calculate the total or tax wrong when shipping is not involved in the discount.

    I remember in some versions patch notes they said it was fixed and I was reliefed, but when I got to test it, it actually wasn't in my or my customers case.

    And the simple change above probably wont fix it either for all.
    Working with Zen Cart since 2003 :: www.prr.fi
    Author of the original Finnish language pack for Zen Cart since 2004

  3. #3
    Join Date
    Jun 2003
    Location
    Newcastle UK
    Posts
    2,896
    Blog Entries
    2
    Plugin Contributions
    2

    Default Re: Coupon Discount Totals Incorrect

    Note

    I cannot reproduce this in v139h.

    Also your figures are still incorrect even with the fix you suggest

    Firstly I have to assume that there is no tax on shipping here.

    This can be inferred from the original VAT amount of 3.33 which is just the VAT on the product (16.67)

    Therefore the correct figure for VAT after discount has been applied is £2.50

    As £20.00 less 25% = 15.00

    Tax included = 15/120*20 = £2.50

    so your checkout should look like

    Sub-Total: £20.00
    Shipping: £5.00
    Discount: £5.00
    VAT: £2.50
    Total: £20.00

  4. #4
    Join Date
    Apr 2011
    Location
    England
    Posts
    16
    Plugin Contributions
    0

    Default Re: Coupon Discount Totals Incorrect

    I know this is an very old thread, but can I just say that duncanad is quite right, assuming that VAT is liable on shipping which is the case in the UK (assuming you use couriers such as TNT, UKMail, ParcelForce, as we do).

    Many thanks duncanad for your post, I'd noticed the discount was always a little bit out but no one ever complained. Still it has been bugging me so I am happy to have had it corrected.

    I'm now going to try to correct the order edit code to correct a different though related and larger problem there.

    BTW we're on 1.3.9h and are about to upgrade (v. late I know), so this may be academic in a few weeks.

 

 

Similar Threads

  1. Swap shipping cost and coupon discount in the checkout totals
    By CheekyCockney in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 26 Aug 2011, 09:53 PM
  2. Incorrect tax calculation when using discount coupon
    By Royal in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 0
    Last Post: 20 Jul 2010, 01:02 PM
  3. Sales Tax incorrect with percentage discount coupon
    By coryinit in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 8
    Last Post: 5 Apr 2010, 03:40 AM

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