Page 1 of 6 123 ... LastLast
Results 1 to 10 of 59
  1. #1
    Join Date
    Aug 2007
    Posts
    118
    Plugin Contributions
    0

    Default Shopping cart Subtotal not equal Checkout Subtotal (rounding error) with GST/VAT

    I have a webshop in Australia, where we use GST-included in our prices. 10%

    I'm getting a rounding error on checkout subtotal. Shopping Cart product totals and Subtotal are calculated correctly but Checkout and subsequent order Subtotals are not.

    Example:

    Price 1.181 * Tax 0.10 = 1.2991
    Rounded = 1.30

    * 10 units

    Subtotal = 13.00

    Shopping Cart is calculating as above, which is correct.


    On checkout (and subsequent confirmed order), sub total is calculated to 12.99, which only makes sense if rounding and/or tax was calculated on subtotal at the checkout/order total stage.


    New, very modded Zen 1.5 site.
    Possible suspects; Store Credits and Rewards Points Module, Super Orders 4.0, Edit Order 4.1.2 or some remnant of uninstalled Fast Easy Checkout. More likely; Stupid GAM user error somewhere

    I've searched the forums and threads on this matter and above add-ons and could not find anything related. Some similar issues but different and normally explained/resolved. I've spent hours now poking through my php files but I just don't understand it well enough to look in the right places I think. I see the code for the Shopping Cart, which I can interpret and identify is calculating correctly. But no idea where the actual calculations are occurring for the Order Total section of the Checkout, and what is saved for the order.

    If someone could at least point me in the right direction I'm likely to find the culprit and fix.

    Cheers
    GAM - the frazzled

    ps. Went live 4:30am Tuesday and mostly sleepless since ... gammods[dot]com[dot]au store

  2. #2
    Join Date
    Jul 2012
    Posts
    4
    Plugin Contributions
    0

    Default Re: Shopping cart Subtotal not equal Checkout Subtotal (rounding error)

    I'm having this problems too but I don't known this problem comes from Zencart core or comes from Ad-on.

  3. #3
    Join Date
    Apr 2007
    Location
    Ontario, Canada
    Posts
    1,731
    Plugin Contributions
    27

    Default Re: Shopping cart Subtotal not equal Checkout Subtotal (rounding error)

    Are you using FEC? And does it happen when you switch to the Classic Green Template?
    Twitch.
    https://www.twitchtoo.com Do you work for free? Please donate.
    Twitch Base8 - Obsidian - This, is what's new.

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Shopping cart Subtotal not equal Checkout Subtotal (rounding error)

    If I apply the calculations in the order that Zen Cart's "standard" processing would do:

    10 x 1.181 = 11.81 x 1.1 (10% tax) = 12.991 ... rounded is 12.99

    So I created a test product in a "stock" Zen Cart v1.5.1 store (using all default settings) that has a price of 1.181. Added 10 of them to my cart. Price displays as 11.80 (incorrect, should be 11.81). I then went to checkout and see the correct subtotal (11.81) with a 1.18 tax (10%) yielding a final price of 12.99.

    That said, I believe that the rounding error is on the shopping_cart page, but I'm not sure (yet) what the culprit is.

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Shopping cart Subtotal not equal Checkout Subtotal (rounding error)

    If you agree with my assertion that the rounding should occur after the per-product-price is multiplied by the cart quantity, then the following changes will move the processing on the shopping_cart page into line with the ot_subtotal calculation. All line numbers are relative to an unmodified v1.5.1 version of the specified file.

    First, /includes/classes/shopping_cart.php, starting at line #850:
    Code:
    //      $this->total += zen_round(zen_add_tax($productTotal, $products_tax), $decimalPlaces) * $qty;
          $this->total += zen_round(zen_add_tax($productTotal, $products_tax) * $qty, $decimalPlaces);  //-lat9-correct rounding issue
    Then, /includes/pages/shopping_cart/header_php.php starting at line #141
    Code:
    //-bof-lat9-fix rounding issue
    //  $ppe = zen_round(zen_add_tax($ppe, zen_get_tax_rate($products[$i]['tax_class_id'])), $currencies->get_decimal_places($_SESSION['currency']));
    //  $ppt = $ppe * $products[$i]['quantity'];
      $ppe = zen_add_tax($ppe, zen_get_tax_rate($products[$i]['tax_class_id']));
      $ppt = zen_round ($ppe * $products[$i]['quantity'], $currencies->get_decimal_places($_SESSION['currency']));
    //-eof-lat9

  6. #6
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,379
    Plugin Contributions
    9

    Default Re: Shopping cart Subtotal not equal Checkout Subtotal (rounding error)

    Similar scenario here on a 1.5.1 shop. Only noted now that the sub-totals are not displaying correctly during checkout if the cart contains multiples of discounted products. The sub-totals were showing correctly in my previous 1.3.9h version of this site.

    item cost $32.35 each, 2 items in cart > shopping cart shows $64.70 (correct)
    getting to checkout payment page and sub-total shows $64.71 (1 cent more ??)

    item cost $31.64 each, 4 items in cart > shopping cart shows $126.56 (correct)
    getting to checkout payment page and sub-total shows $126.54 (2 cents less ??)

    item cost $30.56 each, 6 items in cart > shopping cart shows $183.36 (correct)
    getting to checkout payment page and sub-total shows $183.34 (2 cents less ??)

    It would not matter if I selected a product with quantity discounts or any other product without quantity discounts. But it seems to affect all products with a specials price - say 10% or 15% or whatever percentage off.

    Quote Originally Posted by lat9 View Post
    If you agree with my assertion that the rounding should occur after the per-product-price is multiplied by the cart quantity, then the following changes will move the processing on the shopping_cart page into line with the ot_subtotal calculation. All line numbers are relative to an unmodified v1.5.1 version of the specified file.

    First, /includes/classes/shopping_cart.php, starting at line #850:
    Code:
    //      $this->total += zen_round(zen_add_tax($productTotal, $products_tax), $decimalPlaces) * $qty;
          $this->total += zen_round(zen_add_tax($productTotal, $products_tax) * $qty, $decimalPlaces);  //-lat9-correct rounding issue
    Then, /includes/pages/shopping_cart/header_php.php starting at line #141
    Code:
    //-bof-lat9-fix rounding issue
    //  $ppe = zen_round(zen_add_tax($ppe, zen_get_tax_rate($products[$i]['tax_class_id'])), $currencies->get_decimal_places($_SESSION['currency']));
    //  $ppt = $ppe * $products[$i]['quantity'];
      $ppe = zen_add_tax($ppe, zen_get_tax_rate($products[$i]['tax_class_id']));
      $ppt = zen_round ($ppe * $products[$i]['quantity'], $currencies->get_decimal_places($_SESSION['currency']));
    //-eof-lat9
    Tried your suggestion on a local clone of this site and compared results to the unchanged live site with same products and prices in the cart - to no avail - same result.

    Any other ideas please??

    Thanks / Frank

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

    Default Re: Shopping cart Subtotal not equal Checkout Subtotal (rounding error)

    Frank, it looks like there's a similar change to be made to /includes/classes/order.php, in the cart function:
    Code:
          /*********************************************
           * Calculate taxes for this product
           *********************************************/
    //-bof-20140725-lat9-Correct rounding error
    //     $shown_price = (zen_add_tax($this->products[$index]['final_price'] * $this->products[$index]['qty'], $this->products[$index]['tax']))
    //      + zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']);
          $shown_price = (zen_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'])
          + zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']);
    //-eof-20140725-lat9
          $this->info['subtotal'] += $shown_price;
    I haven't tested this out, but I believe that it will correct the calculations.

  8. #8
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,379
    Plugin Contributions
    9

    Default Re: Shopping cart Subtotal not equal Checkout Subtotal (rounding error)

    Quote Originally Posted by lat9 View Post
    Frank, it looks like there's a similar change to be made to /includes/classes/order.php, in the cart function:
    Code:
          /*********************************************
           * Calculate taxes for this product
           *********************************************/
    //-bof-20140725-lat9-Correct rounding error
    //     $shown_price = (zen_add_tax($this->products[$index]['final_price'] * $this->products[$index]['qty'], $this->products[$index]['tax']))
    //      + zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']);
          $shown_price = (zen_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'])
          + zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']);
    //-eof-20140725-lat9
          $this->info['subtotal'] += $shown_price;
    I haven't tested this out, but I believe that it will correct the calculations.
    Thanks lat9, sadly it's a no go. Bedtime for me, I have a look into includes/classes/currencies.php tomorrow.

  9. #9
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,379
    Plugin Contributions
    9

    Default Re: Shopping cart Subtotal not equal Checkout Subtotal (rounding error)

    Local install - temporarily replaced the following 1.5.1 files with corresponding 1.5.3 files:

    /includes/classes/shopping_cart.php
    /includes/classes/order.php
    /includes/classes/order_total.php

    and sadly getting the same result -->> 1 or 2 cents differnece between cart and checkout pages, so no go again!

  10. #10
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,379
    Plugin Contributions
    9

    Default Re: Shopping cart Subtotal not equal Checkout Subtotal (rounding error)

    Quote Originally Posted by lat9 View Post
    If I apply the calculations in the order that Zen Cart's "standard" processing would do:

    10 x 1.181 = 11.81 x 1.1 (10% tax) = 12.991 ... rounded is 12.99

    So I created a test product in a "stock" Zen Cart v1.5.1 store (using all default settings) that has a price of 1.181. Added 10 of them to my cart. Price displays as 11.80 (incorrect, should be 11.81). I then went to checkout and see the correct subtotal (11.81) with a 1.18 tax (10%) yielding a final price of 12.99.

    That said, I believe that the rounding error is on the shopping_cart page, but I'm not sure (yet) what the culprit is.
    Created a test product with a price of $5.95 (inc tax)

    Tax rate = 10%

    Net before tax = $5.4091. This is the value found stored in the DB table 'products'

    Added 7 items to the cart. Cart sub total is $41.65 (correct - as it should be)

    Checkout payment page shows $41.65 (correct)

    Next I created a special for this product: 10% off

    Product info page shows: $5.95 normal price with a specials price of $5.36 - this is what the customer is seeing (important to note!!)

    Mathematically this is: $5.95 - 10% = $5.355

    Now the cart shows $37.52 which is correct from a customer point of view

    Mathematically this is $5.355 * 7 = $37.485

    Checkout payment page now shows $37.49 . Looks like this is derived from mathematically correct rounding of the previous line which shows $37.485

    It should show the same value as the cart, namely $37.52

    The DB now shows a specials price of $4.8682 for this test product. Add 10% tax and the gross price per unit should be 5.35502 (see the $5.355 above as mathematically calculated)

    So I am thinking that along the trails of scripts and files ZC keeps reverting back to values found in the DB and continues from there instead of just calculating on from the specials price visible to the customer.

    IMHO this appears to be a genuine bug in the logic of ZC ???

    What do you think? Are you able to replicate this on a fresh install - be it 1.5.1 or 1.5.3?

    Cheers / Frank
    Last edited by frank18; 26 Jul 2014 at 10:16 AM.

 

 
Page 1 of 6 123 ... LastLast

Similar Threads

  1. Shopping Cart - Subtotal $0.00
    By dmagic in forum General Questions
    Replies: 1
    Last Post: 9 Apr 2011, 03:38 PM
  2. again tax/VAT being calculated on subtotal ignoring group discount
    By SarahL in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 8
    Last Post: 8 Apr 2008, 06:42 PM
  3. Shopping cart subtotal font color help
    By bigad21 in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 7 Aug 2006, 05:08 AM
  4. Shopping cart subtotal in header
    By businesstoweb in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 13 Jun 2006, 01:32 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