Post by supak111 » Wed Jan 08, 2020 4:24 pm

Can someone please help me fix this error, it's so annoy. I get it dozens of times per day and I can't even figure out why or when it happens.

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

Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by paulfeakins » Wed Jan 08, 2020 6:25 pm

Can you tell us what extensions you have and what you're doing when the error occurs?

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Guru Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by IP_CAM » Wed Jan 08, 2020 9:18 pm


Please don't send me OC Forum Personal Messages, just contact: jti@jacob.ch
---
OC 1.5.6.5 LIGHT Test Site: http://www.bigmax.ch/shop/
OC 1.5.6.5 V-PRO Test Site: http://www.openshop.li/shop/
My Github OC Site: https://github.com/IP-CAM
2'600+ 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 by mona » Wed Jan 08, 2020 10:58 pm

It 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

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.


Spinning Social : Links : Menus : Payments : Socials : Ads : Screen Backgrounds : Galleries : Headers : Banners : Promos


Active Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by letxobnav » Thu Jan 09, 2020 1:00 am

I don't think that uses the convert function in currency.
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.


User avatar
Expert Member

Posts

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

Post by supak111 » Thu Jan 09, 2020 11:10 am

by mona wrote:
Wed Jan 08, 2020 10:58 pm
It 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 have just disabled the auto currency update in settings and will see if that resolves it.

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?

Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by letxobnav » Thu Jan 09, 2020 11:58 am

the 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:

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);
	}
that will print to the php error_log only if one of those values is not numeric along with the currency code.
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.


User avatar
Expert Member

Posts

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

Post by supak111 » Thu Jan 09, 2020 4:15 pm

Tried your first code and got the same error just on different line since I added 9 extra lines
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

Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by letxobnav » Thu Jan 09, 2020 4:38 pm

it does not prevent the warning, it prints the values which cause the warning in your error log.
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.


User avatar
Expert Member

Posts

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

Post by letxobnav » Thu Jan 09, 2020 4:45 pm

as far as I can tell, only these default controller/models use the currency->convert function:

Code: Select all

openbay
voucher
amazon pay
klarna
auspost
ec ship
fedex
usps
google shopping
unless you have an additional extension installed which uses it.

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 supak111 » Thu Jan 09, 2020 9:50 pm

letxobnav wrote:
Thu Jan 09, 2020 11:58 am
the 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:

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);
	}
that will print to the php error_log only if one of those values is not numeric along with the currency code.
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.
added the code above and now got his:

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);

Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by supak111 » Thu Jan 09, 2020 10:00 pm

letxobnav wrote:
Thu Jan 09, 2020 4:45 pm
as far as I can tell, only these default controller/models use the currency->convert function:

Code: Select all

openbay
voucher
amazon pay
klarna
auspost
ec ship
fedex
usps
google shopping
unless you have an additional extension installed which uses it.
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!

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

Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by supak111 » Thu Jan 09, 2020 10:35 pm

Lastes errors are:

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

Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by letxobnav » Fri Jan 10, 2020 12:40 am

first change the function to this to get rid of the notices about the conversions

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.


User avatar
Expert Member

Posts

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

Post by supak111 » Fri Jan 10, 2020 7:10 am

So 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

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
I really wanna know what is causing this damn error so I can fix it properly hopefully

Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by sw!tch » Fri Jan 10, 2020 8:42 am

supak111 wrote:
Fri Jan 10, 2020 7:10 am
So 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

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
I really wanna know what is causing this damn error so I can fix it properly hopefully
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.

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'))) {
with

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'))) { 
Someone else can refine if needed. Also you may need to restore you currency class changes.

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.
Last edited by sw!tch on Fri Jan 10, 2020 11:32 am, edited 4 times in total.

Backup and [ learn how to recover ] before you make any changes.


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by straightlight » Fri Jan 10, 2020 8:52 am

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'))) {
for:

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'))) {

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by supak111 » Fri Jan 10, 2020 10:58 am

I also think a opencart spam bot might be hitting my voucher page since it can't be turned OFF in extensions completely.

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

Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by sw!tch » Fri Jan 10, 2020 11:16 am

See my revised post. Its just one bracket

Backup and [ learn how to recover ] before you make any changes.


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by supak111 » Fri Jan 10, 2020 11:21 am

sw!tch wrote:
Fri Jan 10, 2020 11:16 am
See my revised post. Its just one bracket
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"

Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm
Who is online

Users browsing this forum: No registered users and 39 guests