Page 1 of 6 123 ... LastLast
Results 1 to 10 of 58
  1. #1
    Join Date
    Nov 2006
    Posts
    108
    Plugin Contributions
    0

    Default Different Total Displayed

    On Zen Cart 1.5.7d and 1.5.8.
    I recently set up taxes for all products. Before I did not do this and this problem did not exist.

    I have a product with a net price of 945.4545.
    There is 10% tax, so the gross price is 1040.
    There is no decimal for the currency I use.

    When I put one of this item in the cart, the price displayed during checkout, email and invoice is 1040.
    When I put two of those products in the cart, the price in the shopping cart is 2080, at the checkout_payment, checkout_confirmation, mail and invoice it is 2079. Obviously this is wrong and it should be 2080.

    Anybody has any idea how to fix this?

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,515
    Plugin Contributions
    88

    Default Re: Different Total Displayed

    Thanks for the report. While I don't know how to fix this yet, I will soon.

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

    Default Re: Different Total Displayed

    Hi,
    I see this problem in my shop from time to time. Although I started investigating, I never got the end of it. Here is where I was:
    Successful orders are saved in database and particularly prices for each products are saved in table 'orders_products'. There are saved without tax in field 'products_price' with 4 decimal digits and in field 'final_price' where rounded to 0 decimal as per shop setting.
    Problem seems to be that this rounded value is used when creating invoice (from database) before applying tax.
    A possible solutions would be to save prices tax included... Another one could be to not do any rounding when saving final price. The second one seems easier as there is just to change line 659 in class file 'order.php' but I am not sure of what would be displayed.
    I need to do some testing...

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

    Default Re: Different Total Displayed

    Yes, I believe that calculation (and, obviously, rounding) differences on product pricing need to be different when products-are-displayed-with-tax.

  5. #5
    Join Date
    Nov 2006
    Posts
    108
    Plugin Contributions
    0

    Default Re: Different Total Displayed

    Hi pilou2,
    Quote Originally Posted by pilou2 View Post
    Successful orders are saved in database and particularly prices for each products are saved in table 'orders_products'. There are saved without tax in field 'products_price' with 4 decimal digits and in field 'final_price' where rounded to 0 decimal as per shop setting.
    Problem seems to be that this rounded value is used when creating invoice (from database) before applying tax.
    You are right; that seems to be the origin of the error.
    Quote Originally Posted by pilou2 View Post
    A possible solutions would be to save prices tax included... Another one could be to not do any rounding when saving final price. The second one seems easier as there is just to change line 659 in class file 'order.php' but I am not sure of what would be displayed.
    I need to do some testing...
    I am not sure why in table orders_products products_price is saved with four decimals while final_price is saved as a rounded value.

    The data for total and subtotal for the invoice is pulled from the table orders_total. In this table the value for subtotal is saved rounded and the total value is saved not-rounded.
    It seems there is some inconsistency if values are saved rounded or not-rounded.

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

    Default Re: Different Total Displayed

    Quote Originally Posted by todoonada View Post
    ...I am not sure why in table orders_products products_price is saved with four decimals while final_price is saved as a rounded value...
    Many currencies use two decimals. Using four prevents loosing precision.

    Quote Originally Posted by todoonada View Post
    ..
    The data for total and subtotal for the invoice is pulled from the table orders_total. In this table the value for subtotal is saved rounded and the total value is saved not-rounded.
    It seems there is some inconsistency if values are saved rounded or not-rounded.
    It is not what I have here. In my orders_total table, all numbers (product price, shipping fees, tax, sub-total and total) are saved as displayed in 'text' field and as number not rounded and with four decimals in field 'value' .

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

    Default Re: Different Total Displayed

    I tried saving final-price not rounded in database and it fixed it. I tried both with option to display with tax or not and checked for other possible consequences using developper tool in admin and so far all is good.

    here is what I did:
    Replacing line 659 in ..\includes\classes\order.php
    PHP Code:
    'final_price' => zen_round($products[$i]['price'] + $_SESSION['cart']->attributes_price($products[$i]['id']), $decimals), 
    by this:
    PHP Code:
    'final_price' => $products[$i]['price'] + $_SESSION['cart']->attributes_price($products[$i]['id']), 
    Now, invoices and emails are as they should be.

  8. #8
    Join Date
    Nov 2006
    Posts
    108
    Plugin Contributions
    0

    Default Re: Different Total Displayed

    Quote Originally Posted by pilou2 View Post
    Many currencies use two decimals. Using four prevents loosing precision.
    With "table orders_products products_price is saved with four decimals" I meant that the value is not rounded.


    Quote Originally Posted by pilou2 View Post
    here is what I did:
    Replacing line 659 in ..\includes\classes\order.php
    I can confirm that it works. Yet I am not sure if the code change will have any other complications. There should be a reason why the author of the code rounded the value.

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

    Default Re: Different Total Displayed

    Quote Originally Posted by todoonada View Post
    ...
    I can confirm that it works. Yet I am not sure if the code change will have any other complications. There should be a reason why the author of the code rounded the value.
    There was probably a good reason long time ago... I checked other files code where final_price is used and it is always rounded before displaying at least one time, but most of the time after calculation as it should be done.

  10. #10
    Join Date
    Apr 2008
    Location
    Qld, Australia
    Posts
    257
    Plugin Contributions
    6

    Default Re: Different Total Displayed

    Repeatable in a vanilla version of 1.5.8 and 1.5.8a

    A good example of the error in the original calculation is to create an item including tax with a value of $5. Add 10 items items to the cart and progress to the "Step 2 of 3 - Payment information" screen. The subtotal is $50.05 instead of $50.00
    Repeat for an item priced at $1.60 inc tax. When 10 items are added to the cart the sub-total is $15.95

    Add the two items together to the cart and the sub-total is $16.00 + $50.00 = $66.00 which is correct.

    The change above gives the correct answer for three scenarios.

    Congratulations on posting this fix as I have been hunting for an answer for along time.
    OldNGrey
    ZC158a PHP 8.2.15
    MySQL 10.6.16-MariaDB

 

 
Page 1 of 6 123 ... LastLast

Similar Threads

  1. Replies: 5
    Last Post: 3 Apr 2020, 07:53 PM
  2. v151 Site that displayed different templates.
    By Malaperth in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 3 Feb 2014, 07:38 PM
  3. v151 order total different from cart total
    By s_p_ike in forum Bug Reports
    Replies: 9
    Last Post: 9 Dec 2012, 09:29 AM
  4. Different Product Listing styles displayed
    By skelly100 in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 31 Dec 2009, 11:33 PM
  5. Free shipping for Different sales total for different zones
    By francesca_ph in forum Built-in Shipping and Payment Modules
    Replies: 20
    Last Post: 30 Dec 2008, 05:43 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