Post by mrblond » Sat Jun 30, 2018 1:06 am

My Opencart version 3.0.2.0
I use Four currencies. The default is Euro. Value of All currencies is up to two decimals: 1.170000 etc.
Store prices set in Euro are also up to two decimals: 3.9800 etc.
When proceeding the checkout in Euro everything is Okay.
When proceeding the checkout in other currency, there is often error with 0.01 in the total sum. Sometimes this error is in products Sum and sometimes it is in the sum product+shipping cost. I don't have any other taxes in the checkout.

For example:
Product 1 = 3.20CHF
Product 2 = 4.58CHF
Sub-Total: 7.77CHF (wrong with -0.01)

or:
Product 1 = 5.83USD
Shipping = 0.59USD
Total: 6.41USD (wrong with -0.01)

When the sum is wrong, the checkout results in error in connecting with the payment method page.
So, Opencart can not work with other currencies aside of the default.

Why is that? How to be solved?

Active Member

Posts

Joined
Fri Oct 13, 2017 4:43 pm

Post by mrblond » Sun Jul 01, 2018 12:13 am

Actually, it is clear what is the problem but how to be solved?
This is a real bug in Opencart!?!?

The products and the shipping are listed in shopping cart (and respectively in the invoice) rounded to two decimals, which is okay.
But the Sub-total and the Total are sum of not rounded prices.
For example: Default product price: 4.98EUR and Shipping 0.50EUR, when one changes the currency to USD (1EUR=1.17USD):
in the table and invoice it is rounded:
Product 1 = 5.83USD
Shipping = 0.59USD

but Opencart sums in the background:
Product 1 = 5.8266USD + Shipping = 0.585USD and then round it in the Total=6.41USD which is different from the sum of the prices in the table which is 6.42USD.
As a result, when the checkout is confirmed, the bank module doesn't accept it and opens error page.

How to make the cart to sum the initially rounded prices which are shown in the table?

Active Member

Posts

Joined
Fri Oct 13, 2017 4:43 pm

Post by IP_CAM » Sun Jul 01, 2018 1:48 am

Well, this Extension might be of help on such:
---
Price Rounding
https://www.opencart.com/index.php?rout ... n_id=10016
---
found here:
https://www.opencart.com/index.php?rout ... arch=round
---
This always has been a potential problem, as it looks, and
according to older topics, but I never made any tests, to be able to judge.
Good Luck!
Ernie
---
Image

I am no longer active at the Forum. Please do NOT send me Personal Mails,
they will no longer be replied to.
My Github OC Site: https://github.com/IP-CAM
4'100 + FREE OC Extensions, on the World's largest Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by mrblond » Sun Jul 01, 2018 5:29 am

Isn't it be easier somebody to tell me what code lines to change in some .php file?
I can't believe such a huge bug to exist and Opencart developers do nothing!
Shouldn't we tell the world that Opencart can't work with multiple currencies.

So, people, what is the solution?

Active Member

Posts

Joined
Fri Oct 13, 2017 4:43 pm

Post by mrblond » Tue Jul 03, 2018 5:27 pm

No help!

Is this bug exist in other versions?
Should I downgrade to 2.0 or wait for new version?

Active Member

Posts

Joined
Fri Oct 13, 2017 4:43 pm

Post by julian70400 » Wed Mar 06, 2019 11:52 pm

Hello, did you find a solution ?

Newbie

Posts

Joined
Thu Jun 14, 2018 10:44 pm

Post by letxobnav » Thu Mar 07, 2019 1:46 am

you might try in currency class:

change:
$amount = $value ? (float)$number * $value : (float)$number;

into:
$amount = $value ? (float)$number * round($value,(int)$decimal_place) : (float)$number;

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by IP_CAM » Thu Mar 07, 2019 4:22 am

into: $amount = $value ? (float)$number * round($value,(int)$decimal_place) : (float)$number;
Well, by trying this (matched to my OC Version) in my file, it ended up
to result in one price, i.E. 400.00, shown in all currencies used. :choke:

But I also compared the v.3.1.0.0.a File with my 1.5.6.x Version File, and
found out, that my ROUNDING Code looks quite similar in v.3.x Versions.
By setting it to 1, (v.3.x - $amount, 1) (v.1.5.x - $value, 1) it results in 'even'
Numbers (00/10/20) only, and 01 - 09 will no longer exist. It a Product Price
results in 88.88 or 99.99, by a (v.3.x - $amount, 1) (v.1.5.x - $value, 1) Setting,
it will show/use 89.00 or 100.00 Values.
This might not please Germans, and others, still using single-cent Amounts,
I'm aware of that, but for some, it might be of help, if it works in your Version.
And depending on that (v.3.x - $amount, x) (v.1.5.x - $value, x) it could more
precisely meet specific needs of some of you.

Just in Case ..., and untested in later than OC 1.5.6.5_rc Versions. :D
Ernie
---
Image

I am no longer active at the Forum. Please do NOT send me Personal Mails,
they will no longer be replied to.
My Github OC Site: https://github.com/IP-CAM
4'100 + FREE OC Extensions, on the World's largest Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by victorj » Thu Mar 07, 2019 4:33 am

make sure you have your currency calculated to 8 decimals.
if you have price including tax on your site, product price is calculated in 4 decimals, make sure you calculate them into 8 decimals.
to do so you wil have to alter in product table the price from 15.4 to 15.8
when entering product price enter with 8 decimals, there are mods that will allow you to input price and calculate ex tax price up to 8 decimals.

Now when prices are calculated from one currency to another or when large sums are ordered correct totals are calculated.

Koeltechnische deurrubbers eenvoudig online op maat bestellen.
Alle niet stekplichtige onderdelen zoals scharnieren, sloten, randverwarming en verlichting voor alle typen koelingen en vriezers.
https://koelcel-onderdelen.com


User avatar
Expert Member

Posts

Joined
Sat Jun 25, 2011 4:09 am
Location - Alkmaar Holland

Post by letxobnav » Thu Mar 07, 2019 8:47 am

I am using 3.0.2.0.
My default currency is Taiwan dollar with 0 decimal places.
JPY is set to 0 decimal places.
All others have 2 decimal places.

so far with

Code: Select all

$amount = $value ? (float)$number * round($value,(int)$decimal_place) : (float)$number;
all non-default currencies, USD,GBP,EURO,JPY seem ok with regard to rounding.

I guess you need to round the numbers to the decimals you display before using them in the calculations.

I must admit, I do not use the tax classes (my prices include those) so you may have to double check if you do.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by letxobnav » Thu Mar 07, 2019 8:53 am

to be sure, I am talking about the $amount calculation:

Code: Select all

$amount = $value ? (float)$number * round($value,(int)$decimal_place) : (float)$number;
not the number_format call:

Code: Select all

$string .= number_format($amount, (int)$decimal_place, $this->language->get('decimal_point'), $this->language->get('thousand_point'));
which comes later.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by julian70400 » Thu Mar 07, 2019 5:59 pm

letxobnav wrote:
Thu Mar 07, 2019 1:46 am
you might try in currency class:

change:
$amount = $value ? (float)$number * $value : (float)$number;

into:
$amount = $value ? (float)$number * round($value,(int)$decimal_place) : (float)$number;
Hello,

Are you answering this to me ? If yes, in which file ?

Newbie

Posts

Joined
Thu Jun 14, 2018 10:44 pm

Post by letxobnav » Thu Mar 07, 2019 6:19 pm

system/library/cart/currency.php

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by julian70400 » Fri Mar 29, 2019 5:31 pm

Hello,

THanks, but still same problem :

I am able to reproduce more specifically it :

If a add 130 items with 5.5% of taxe with a price of 5€ ==> everything is fine
If a add 129 items with 5.5% of taxe with a price of 5€ ==> 0.1cents is missing on final price
If a add 129 (and more) items with 20% of taxe with a price of 5€ ==> everything is fine
If a add 129 items (and more) with 5.5% of taxe with a price of 6€ (and more or less) ==> everything is fine

What's wrong ?? This problem occured on each items which are in this case. It seem to be related to price and taxe.

Got a demo here with another cart.

Any idea ?

FYI, got this in the currency.php :

Code: Select all

                $amount = $value ? (float)$number * $value : (float)$number;

                $amount = round($amount, (int)$decimal_place);

Newbie

Posts

Joined
Thu Jun 14, 2018 10:44 pm

Post by letxobnav » Fri Mar 29, 2019 5:44 pm

like I mentioned, I do not use the tax classes but I suspect the same issue occurs there, calculations with numbers having different decimal digits.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by julian70400 » Fri Mar 29, 2019 5:52 pm

letxobnav wrote:
Fri Mar 29, 2019 5:44 pm
like I mentioned, I do not use the tax classes but I suspect the same issue occurs there, calculations with numbers having different decimal digits.
What do you suggest to do in my case ? Thanks.

Newbie

Posts

Joined
Thu Jun 14, 2018 10:44 pm

Post by letxobnav » Fri Mar 29, 2019 6:07 pm

well, have not checked it myself as I do not use them but you might fancy experimenting with the functions:

public function calculate($value, $tax_class_id, $calculate = true) {

and

public function getRates($value, $tax_class_id) {

in the tax class: system/library/cart/tax.php

there is where the tax calculations take place.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by julian70400 » Mon Apr 01, 2019 6:20 pm

thanks !

Newbie

Posts

Joined
Thu Jun 14, 2018 10:44 pm

Post by xseon » Sun Feb 07, 2021 5:08 am

I use the following modification and it seems it solves the problem:

Code: Select all

    <file path="system/library/cart/cart.php">
        <operation>
            <search><![CDATA[($tax_rate['amount'] * $product['quantity'])]]></search>
            <add position="replace"><![CDATA[round(($tax_rate['amount'] * $product['quantity']),2)]]></add>
        </operation>
    </file>

Deeper and Better Category Module
Mass Product Price Change


User avatar
New member

Posts

Joined
Thu Dec 01, 2011 3:04 pm
Location - Bulgaria
Who is online

Users browsing this forum: No registered users and 9 guests