PHP Warning: A non-numeric value encountered in ***/public_html/system/library/cart/currency.php on line 69
This thread talk about it but its not a solution viewtopic.php?t=207997
~ OC 3.0.3.2 and OCmods only ~
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
viewtopic.php?f=181&t=215530&p=773521#p773521
https://github.com/opencart/opencart/pull/7785/files
My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.
ADMIN => SETTINGS => local tab
and turn off auto update
if that is your problem
viewtopic.php?t=202301
DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.
https://www.youtube.com/watch?v=zXIxDoCRc84
It is used in many payment extensions.
just add some traces before line 69 to see which value is the issue which perhaps can give a clue where it comes from.
Code: Select all
public function convert($value, $from, $to) {
if (isset($this->currencies[$from])) {
$from = $this->currencies[$from]['value'];
} else {
$from = 1;
}
if (isset($this->currencies[$to])) {
$to = $this->currencies[$to]['value'];
} else {
$to = 1;
}
// tracing start
error_log('value: '.$value);
error_log('to: '.$to);
error_log('from: '.$from);
// tracing end
return $value * ($to / $from);
}
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.
I have just disabled the auto currency update in settings and will see if that resolves it.by mona wrote: ↑Wed Jan 08, 2020 10:58 pmIt might be because of the update auto currency.
ADMIN => SETTINGS => local tab
and turn off auto update
if that is your problem
viewtopic.php?t=202301
I do have an extension for manually updating currency, it uses http://alphavantage.co API.
I also don't know when it happens, it seems to be random. I've done testing to try to reproduce it but it never happens when I'm poking around.
I will also add those traces, can you explain what that will tell me?
~ OC 3.0.3.2 and OCmods only ~
input are the value, from currency and to currency.
based on the input it uses the from/to exchange rates and the value to produce a new value using the calculation $value * ($to / $from).
php is complaining that one of those is not a number as calculating with a non-number is not so good.
so the error_log statements print out the contents of $value, $to and $from before it does the calculation so you can see which is not a number.
perhaps better to replace the entire function with:
Code: Select all
public function convert($value, $from, $to) {
if (isset($this->currencies[$from])) {
$from_value = $this->currencies[$from]['value'];
} else {
$from_value = 1;
}
if (isset($this->currencies[$to])) {
$to_value = $this->currencies[$to]['value'];
} else {
$to_value = 1;
}
// tracing start
if (!is_numeric($value)) error_log('CONVERT NON-NUMERIC VALUE: '.$value);
if (!is_numeric($to)) error_log('CONVERT NON-NUMERIC TO_VALUE: '.$this->currencies[$to].' '.$to_value);
if (!is_numeric($value)) error_log('CONVERT NON-NUMERIC FROM_VALUE: '.$this->currencies[$from].' '.$from_value);
// tracing end
return $value * ($to_value / $from_value);
}
I had to rename some of the variables to retain the currency reference as the original overwrites it's own input variables which is rather dumb.
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.
PHP Warning: A non-numeric value encountered in public_html/system/library/cart/currency.php on line 77
I'll try using your new code and see what happens.
PS turning off currency update in setting didn't help I guess since I got the error again
~ OC 3.0.3.2 and OCmods only ~
So what is in your error log (the php error log).
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.
Code: Select all
openbay
voucher
amazon pay
klarna
auspost
ec ship
fedex
usps
google shopping
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.
added the code above and now got his:letxobnav wrote: ↑Thu Jan 09, 2020 11:58 amthe convert function in the currency class converts currency values.
input are the value, from currency and to currency.
based on the input it uses the from/to exchange rates and the value to produce a new value using the calculation $value * ($to / $from).
php is complaining that one of those is not a number as calculating with a non-number is not so good.
so the error_log statements print out the contents of $value, $to and $from before it does the calculation so you can see which is not a number.
perhaps better to replace the entire function with:
that will print to the php error_log only if one of those values is not numeric along with the currency code.Code: Select all
public function convert($value, $from, $to) { if (isset($this->currencies[$from])) { $from_value = $this->currencies[$from]['value']; } else { $from_value = 1; } if (isset($this->currencies[$to])) { $to_value = $this->currencies[$to]['value']; } else { $to_value = 1; } // tracing start if (!is_numeric($value)) error_log('CONVERT NON-NUMERIC VALUE: '.$value); if (!is_numeric($to)) error_log('CONVERT NON-NUMERIC TO_VALUE: '.$this->currencies[$to].' '.$to_value); if (!is_numeric($value)) error_log('CONVERT NON-NUMERIC FROM_VALUE: '.$this->currencies[$from].' '.$from_value); // tracing end return $value * ($to_value / $from_value); }
I had to rename some of the variables to retain the currency reference as the original overwrites it's own input variables which is rather dumb.
2020-01-09 6:34:05 - PHP Notice: Array to string conversion in /public_html/system/library/cart/currency.php on line 76
2020-01-09 6:34:05 - PHP Notice: Array to string conversion in /public_html/system/library/cart/currency.php on line 77
2020-01-09 6:34:05 - PHP Warning: A non-numeric value encountered in/public_html/system/library/cart/currency.php on line 79
which would be
Code: Select all
76: if (!is_numeric($to)) error_log('CONVERT NON-NUMERIC TO_VALUE: '.$this->currencies[$to].' '.$to_value);
77: if (!is_numeric($value)) error_log('CONVERT NON-NUMERIC FROM_VALUE: '.$this->currencies[$from].' '.$from_value);
// tracing end
79: return $value * ($to_value / $from_value);
~ OC 3.0.3.2 and OCmods only ~
Since I don't use any of the above, only voucher (which I don't even need), I went digging and round it!!! If I try to purchase a voucher with the "Amount" field empty I get this error to show up every time!letxobnav wrote: ↑Thu Jan 09, 2020 4:45 pmas far as I can tell, only these default controller/models use the currency->convert function:
unless you have an additional extension installed which uses it.Code: Select all
openbay voucher amazon pay klarna auspost ec ship fedex usps google shopping
NOW is there any way to edit the voucher module so if someone leave the field empty I don't keep seeing the error?
PS I just tried disabling the Voucher extension but I can still access it under ***.com/index.php?route=account/voucher
~ OC 3.0.3.2 and OCmods only ~
Code: Select all
2020-01-09 8:18:46 - PHP Notice: Array to string conversion in/public_html/system/library/cart/currency.php on line 76
[09-Jan-2020 08:18:46 America/Chicago] CONVERT NON-NUMERIC TO_VALUE: Array 1.00000000
[09-Jan-2020 08:18:46 America/Chicago] CONVERT NON-NUMERIC TO_VALUE: Array 1.00000000
~ OC 3.0.3.2 and OCmods only ~
Code: Select all
public function convert($value, $from, $to) {
if (isset($this->currencies[$from])) {
$from_value = $this->currencies[$from]['value'];
} else {
$from_value = 1;
}
if (isset($this->currencies[$to])) {
$to_value = $this->currencies[$to]['value'];
} else {
$to_value = 1;
}
// tracing start
if (!is_numeric($value)) error_log('CONVERT NON-NUMERIC VALUE: '.$value);
if (!is_numeric($to_value)) error_log('CONVERT NON-NUMERIC TO_VALUE: '.$to.' '.$to_value);
if (!is_numeric($from_value)) error_log('CONVERT NON-NUMERIC FROM_VALUE: '.$from.' '.$from_value);
// tracing end
return $value * ($to_value / $from_value);
}
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.
Code: Select all
2020-01-09 12:24:00 - PHP Notice: Array to string conversion in /public_html/system/library/cart/currency.php on line 76
2020-01-09 12:24:00 - PHP Notice: Array to string conversion in /public_html/system/library/cart/currency.php on line 77
2020-01-09 12:24:00 - PHP Warning: A non-numeric value encountered in /public_html/system/library/cart/currency.php on line 79
~ OC 3.0.3.2 and OCmods only ~
Interesting in voucher.php.. I can't test this live at the moment, but looks like there is no numeric check. It's using the currency class to validate.supak111 wrote: ↑Fri Jan 10, 2020 7:10 amSo I gave it some hours and it looks like its not voucher page issue. Its something else that constantly giving me these errors. Error I get in storage/logs/oc_error.log
I really wanna know what is causing this damn error so I can fix it properly hopefullyCode: Select all
2020-01-09 12:24:00 - PHP Notice: Array to string conversion in /public_html/system/library/cart/currency.php on line 76 2020-01-09 12:24:00 - PHP Notice: Array to string conversion in /public_html/system/library/cart/currency.php on line 77 2020-01-09 12:24:00 - PHP Warning: A non-numeric value encountered in /public_html/system/library/cart/currency.php on line 79
Untested, but you can try :
catalog/controller/account/voucher.php
Replace:
Code: Select all
if (($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) < $this->config->get('config_voucher_min')) || ($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) > $this->config->get('config_voucher_max'))) {
Code: Select all
if ((!isset($this->request->post['amount'])) || (!is_numeric($this->request->post['amount'])) || ($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) < $this->config->get('config_voucher_min')) || ($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) > $this->config->get('config_voucher_max'))) {
Edit:
Updated to also include the !isset($this->request->post['amount'] check as mentioned by @straightlight below, appears that was also missing in the validate method.
This should resolve the non-numeric value in currency from vouchers. My guess is bots are hitting that page and is the source of your error, unless you are using some other extension not listed above.
Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!
Code: Select all
if ((!is_numeric($this->request->post['amount'])) || ($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) < $this->config->get('config_voucher_min')) || ($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) > $this->config->get('config_voucher_max'))) {
Code: Select all
if ((!isset($this->request->post['amount'])) || (!is_numeric($this->request->post['amount'])) || ($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) < $this->config->get('config_voucher_min')) || ($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) > $this->config->get('config_voucher_max'))) {
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
The code you guys suggested above, one code has 1 "{" at the end and the other code has 2 "{ {" at the end, which is correct? To me it looks like 1 "{" but I'm pretty bad at coding
~ OC 3.0.3.2 and OCmods only ~
Awesome thanks, its seems to work perfect. I hope I never see that darn error ever again.
One other question, what do you mean by: "Also you may need to restore you currency class changes"
~ OC 3.0.3.2 and OCmods only ~
Users browsing this forum: lockbox, Semrush [Bot] and 95 guests