Re: Different Total Displayed
Thanks for the quick response, @pilou2, it is much appreciated. I'm off to configure my testing site with that information and will hopefully have some idea of where the issue lies later today.
The sub-total calculations for the shopping-cart page's display are performed by the page's header_php.php, first via call to the shopping-cart class' show_total method, with the returned value then formatted into the currently-selected currency.
During the checkout, the subtotal calculation is performed within the order-class' cart method. The overall total and tax are further manipulated by the various order-total modules to produce the order's final tax and total.
Re: Different Total Displayed
Quote:
Originally Posted by
lat9
Thanks for the quick response, @pilou2, it is much appreciated. I'm off to configure my testing site with that information and will hopefully have some idea of where the issue lies later today.
The sub-total calculations for the shopping-cart page's display are performed by the page's header_php.php, first via call to the shopping-cart class' show_total method, with the returned value then formatted into the currently-selected currency.
During the checkout, the subtotal calculation is performed within the order-class' cart method. The overall total and tax are further manipulated by the various order-total modules to produce the order's final tax and total.
Thanks, I come back here if I find something interesting.
Re: Different Total Displayed
@pilou2, is the site displaying prices with tax or not?
Re: Different Total Displayed
Quote:
Originally Posted by
lat9
@pilou2, is the site displaying prices with tax or not?
Never mind, you have fully identified the cases in post #43 of this thread.
Re: Different Total Displayed
Cart page is now fixed but code still need lots of testing because of all possible discount, attributes and other free stuffs.
I made a branch for that on my ZC fork: https://github.com/piloujp/zencart/tree/Currency-prices
For checkout page, nothing is done yet.
Re: Different Total Displayed
Yep, I'm pretty close on an overall solution that appears to work properly for the issues identified here by @todoonada, @pilou2 and @OldNGrey; I'll post back here when that Zen Cart pull-request (PR) has been updated.
Re: Different Total Displayed
Quote:
Originally Posted by
lat9
Yep, I'm pretty close on an overall solution that appears to work properly for the issues identified here by @todoonada, @pilou2 and @OldNGrey; I'll post back here when that Zen Cart pull-request (PR) has been updated.
PR updated. All cases reported in this thread (and a couple from clients) validated as corrected.
Re: Different Total Displayed
Quote:
Originally Posted by
lat9
PR updated. All cases reported in this thread (and a couple from clients) validated as corrected.
Hello lat9,
thank you for the work you put into it.
I do not have the time to test at the moment.
I made a bit of a hack to solve the problem, so it works for me at the moment. However it is not a reasonable solution to go into main Zen Cart code.
Re: Different Total Displayed
Quote:
Originally Posted by
lat9
PR updated. All cases reported in this thread (and a couple from clients) validated as corrected.
I tried the new PR.
For files header.php and shopping_cart.php I did exactly the same modifications at first, and it did correct issues discussed in this thread but re-introduced an old one...
Which is that the last digit has a one unit shift when using another currency. It appears only in total when displaying prices without tax, and it is also in subtotal when displaying prices with tax.
Problem comes from calculation logic.
For cart calculation, products price (in main currency) has tax added and then is being converted to new currency, all this one by one.
In this case, all prices are rounded one by one when conversion is done.
For subtotal or total calculation, all products prices in main currency are added then tax apply, then currency conversion.
In this case, all products prices are added then rounding is done at conversion time.
Unfortunately, due to rounding errors, total in both calculation can have a difference of one unit on the last digit.
With numbers I gave you and a conversion rate of 155 and tax at 10%, I got 1 yen difference at the end.
In cart (with tax displayed):
48.34 x 1.1 = 53.174 x 155 = 8241.97 rounded to 8242
35.00 x 1.1 = 38.5 x 155 = 5967.5 rounded to 5968
-------------------------------------------------
Total: 14210
subtotal calculation:
48.34 + 35.00 = 83.34 x 1.1 = 91.674 x 155 = 14209.47 rounded to 14209
My idea to fix it, that I applied in shopping_cart.php, is to do conversion and rounding on each price before adding them, when calculating subtotal or total:
((48.34 x 155 = 7492.7 rounded to 7493) + (35.00 x 155 = 5425)) = 12918 x 1.1 = 14209.8 rounded to 14210
With all possible prices modification by discounts, attributes and others it makes this modification pretty complicated...
Re: Different Total Displayed
I updated the GitHub branch with something that seems to do the job. https://github.com/piloujp/zencart/tree/Currency-prices
No more penny loss, numbers add perfectly except when using a secondary currency and a shipping module with tax class, then shipping tax is missing from the total. It is included in tax or shipping cost depending on tax display option, but always missing in total...
When using main currency, everything is perfect! If you have an idea of what is going on...
Attributes and discount stuffs have not been tested yet.