@todoonada and @OldNGrey, what's the value in use for Configuration :: My Store :: Currency Conversion Ratio?
@todoonada and @OldNGrey, what's the value in use for Configuration :: My Store :: Currency Conversion Ratio?
Item #608 products_price = 118.7727
Configuration :: My Store :: Currency Conversion Ratio = 1.025
OldNGrey
ZC158a PHP 8.2.15
MySQL 10.6.16-MariaDB
@OldNGrey and @todoonada, please see this PR: https://github.com/zencart/zencart/pull/6319
I've verified that the changes correct each of the issues identified in this thread and would appreciate some 3rd-party validation!
Using this PR, I did some testing changing all I can, price, tax display and value... As long as I use main currency, calculation was all good. But when using another currency, things get weird...
Second currency rate is 155 and tax is 10%, no decimal. I have two products in cart, one is priced at 48.34 (53.174 with tax) and the other is at 35 (38.5 w.tax).
When not displaying tax:
I got in cart product price 1 at 7440 (instead of 7493) and product 2 at 5425 as it should be.
In last checkout screen, product price 1 is still wrong, but all calculations are correct for these prices (7440 and 5425).
When displaying prices with tax:
I got in cart product price 1 at 8215 (instead of 8242) and product 2 at 6045 (instead of 5968).
In last checkout screen, product price 1 is 8242 and product 2 is 5968 as they should be but subtotal (14260 instead of 14210) and tax (1296 instead of 1292) are wrong. Total is 15035, which I have no idea how it ends to this value...
I am not sure if it is related to tax calculation, it might be more of a rounding problem when converting currencies.
Last edited by pilou2; 13 Mar 2024 at 07:51 PM.
From my testing with the conversion from AUD to EUR, or any other currency I have set, the display for payment information is now correct.
Thank you Lat9
OldNGrey
ZC158a PHP 8.2.15
MySQL 10.6.16-MariaDB
I think I figured out part of the problem. In my currency with rate 155 (JPY) I use 0 decimal. It seems that currency conversion in cart rounds to 0 decimals before conversion:
Product price 48.34 becomes 48 which multiply by 155 gives 7440 which is exactly the wrong price I got in cart without tax.
Second product price 35.00 has 0 as decimal. This is why price after conversion is still right. I don't know where it is in the code yet.
When displaying prices with tax:
Product 1: 48.34 x 1.1 = 53.174 ----> 53 x 155 = 8215 Which is what I got.
Product 2: 35.00 x 1.1 = 38.5 ----> 39 x 155 = 6045 Which is what I got too!
Rounding to new decimal setting should be done after conversion.
Calculation in last checkout screen is different and there might be something else to figure out...
Thank you for taking the time to check this out. It would help me to reproduce and then correct the issue if I could verify:
Store currency, number of decimal digits (sounds like 2)
What is the 1.1 that multiplies the product pricing, for example 48.34 x 1.1 = 53.174
Store currency, converted to JPY with a 155 conversion rate.
The main currency is default US$. I use a default cart with demo data to which I added Japanese yen as currency with rate (including factor 1.05) of 155 (155.00000000) and has 0 decimal. Then I modified Tax to apply worldwide and at a 10% rate which makes it easier for debugging. Then, I modified some products prices and one is 48.3400 without tax and the other is 35.0000 without tax too.
Now, I suppose you understand 48.34 (price w.o.t.) x 1.1 (10% tax).
1.1 is 1 + 10/100...
I looked at the code and find some rounding (line 118 in shopping cart header and some in shopping cart class) I can suppress to get correct prices, but then the 'one digit off' bug comes back. I think these rounding were added to correct this bug, but in fact hide it.
Probably, the right thing to do would be to do a rounding after currency conversion (if necessary) but before any other calculation like adding tax, then a last rounding before displaying.
I could not find where currency conversion is done for subtotals. It seems subtotal is calculated differently depending on page you are: cart, checkout payment and checkout confirmation... If you know where this currency conversion is done, please let me know.
Bookmarks