Page 1 of 1

[Solved] Warning: Missing argument 2 for Cart\Currency::format()

Posted: Sun Apr 30, 2017 11:57 pm
by HAO
I tried to upgrade my payment module to OpenCart 2.3.0.2, But a similar error message appears.

Code: Select all

Warning: Missing argument 2 for Cart\Currency::format(), called in catalog/model/extension/shipping/ecpaylogistic.php on line 65 and defined in 2302/system/library/cart/currency.php on line 24
Notice: Undefined variable: currency in 2302/system/library/cart/currency.php on line 25
Notice: Undefined index: in 2302/system/library/cart/currency.php on line 25
Notice: Undefined variable: currency in 2302/system/library/cart/currency.php on line 26
Notice: Undefined index: in 2302/system/library/cart/currency.php on line 26
Notice: Undefined variable: currency in 2302/system/library/cart/currency.php on line 27
Notice: Undefined index: in 2302/system/library/cart/currency.php on line 27
Notice: Undefined variable: currency in 2302/system/library/cart/currency.php on line 30
Notice: Undefined index: in 2302/system/library/cart/currency.php on line 30
catalog/model/extension/shipping/ecpaylogistic.php Code:

Code: Select all

			if ($ecpaylogisticSetting['ecpaylogistic_unimart_status']) {
				$shipping_cost = ($isFreeShipping) ? 0 : $ecpaylogisticSetting['ecpaylogistic_unimart_fee'];
				$quote_text = (strpos(VERSION, '2.2.') !== false) ? $this->currency->format($shipping_cost, $this->session->data['currency']) : $this->currency->format($shipping_cost);
				$quote_data['unimart'] = array(
						'code'         => 'ecpaylogistic.unimart',
						'title'        => $this->language->get('text_unimart'),
						'cost'         => $shipping_cost,
						'tax_class_id' => 0,
						'text'         => $quote_text,
				);
				$Extra['last_ecpaylogistic_shipping_code'] = 'unimart';
			}
Looks like this should be a problem:

Code: Select all

$quote_text = (strpos(VERSION, '2.2.') !== false) ? $this->currency->format($shipping_cost, $this->session->data['currency']) :
How can I fix it?

Re: Warning: Missing argument 2 for Cart\Currency::format()

Posted: Mon May 01, 2017 2:51 pm
by imdevlper18
Hi,

Since you are on 2.3.x version.
Change this code

Code: Select all

$quote_text = (strpos(VERSION, '2.2.') !== false) ? $this->currency->format($shipping_cost, $this->session->data['currency']) : $this->currency->format($shipping_cost);
To this

Code: Select all

$quote_text = $this->currency->format($shipping_cost, $this->session->data['currency']);

Re: Warning: Missing argument 2 for Cart\Currency::format()

Posted: Mon May 01, 2017 2:51 pm
by pprmkr

Code: Select all

$quote_text = (strpos(VERSION, '2.2.') !== false) ? $this->currency->format($shipping_cost, $this->session->data['currency']) : $this->currency->format($shipping_cost);
This returns 'false' on version 2.3.0.2 and will use $this->currency->format($shipping_cost);

Better use PHp function 'version_compare' ( http://php.net/manual/en/function.version-compare.php ) :

Code: Select all

$quote_text = version_compare(VERSION, '2.2.0.0', '>=') ? $this->currency->format($shipping_cost, $this->session->data['currency']) : $this->currency->format($shipping_cost);

Re: Warning: Missing argument 2 for Cart\Currency::format()

Posted: Mon May 01, 2017 9:58 pm
by HAO
Thank you for your reply!

The problem has been solved!