PHP Warning: Creating default object from empty value

  • Posts: 323
  • Thank you received: 18
  • Hikashop Business
4 years 3 weeks ago #326950

-- HikaShop version -- : 4.4.0
-- Joomla version -- : 3.9.23
-- PHP version -- : 7.3.24

This is filing my error log almost every second:
PHP Warning: Creating default object from empty value in administrator/components/com_hikashop/classes/currency.php on line 2505

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
4 years 2 weeks ago #326970

Hi,

Please try to add the code:

else
						$payment->taxes[$tax->tax_namekey] = new stdClass();
after the code:
if(is_object($tax))
						$payment->taxes[$tax->tax_namekey] = clone($tax);
in the file administrator/components/com_hikashop/classes/currency.php and it should hopefully fix the warning message.
Please report the result so that we can add the modification for the next version of HikaShop.
That way you won't have to redo the modification after the next update and others won't get the warning in the future.

Please Log in or Create an account to join the conversation.

  • Posts: 323
  • Thank you received: 18
  • Hikashop Business
4 years 2 weeks ago #326980

Now I have Warning: Creating default object from empty value in administrator/components/com_hikashop/classes/currency.php on line 2507

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
4 years 2 weeks ago #327047

Mmm. That means we probably don't have the same code on the same line.
Could you edit the file administrator/components/com_hikashop/classes/currency.php on your website and tell me what you have around the line 2507 and which one is the line 2507

Please Log in or Create an account to join the conversation.

  • Posts: 323
  • Thank you received: 18
  • Hikashop Business
4 years 2 weeks ago #327049

From line 2499 to line 2519

if($payment->payment_price_with_tax != $payment->payment_price) {
				if(!isset($payment->taxes) && isset($total->prices[$k]->taxes) && is_array($total->prices[$k]->taxes)) {
					$payment->taxes = array();
					$tax = reset($total->prices[$k]->taxes);
					if(is_object($tax))
						$payment->taxes[$tax->tax_namekey] = clone($tax);
					$payment->taxes[$tax->namekey]->tax_amount = $payment->payment_price_with_tax - $payment->payment_price;
					$payment->taxes[$tax->namekey]->amount = $payment->payment_price;
				}
				if(!empty($payment->taxes)) {
					foreach($payment->taxes as $tax) {
						if(isset($total->prices[$k]->taxes[$tax->tax_namekey])) {
							$total->prices[$k]->taxes[$tax->tax_namekey]->tax_amount += $tax->tax_amount;
							$total->prices[$k]->taxes[$tax->tax_namekey]->amount += $tax->amount;
						} else
							$total->prices[$k]->taxes[$tax->tax_namekey] = clone($tax);
					}
				}
			}
		}
	}

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
4 years 2 weeks ago #327055

Hi,

Ok. I think I've found the issue.
Change the code:

if(is_object($tax))
						$payment->taxes[$tax->tax_namekey] = clone($tax);
					$payment->taxes[$tax->namekey]->tax_amount = $payment->payment_price_with_tax - $payment->payment_price;
					$payment->taxes[$tax->namekey]->amount = $payment->payment_price;
to:
if(is_object($tax) && !empty($tax->tax_namekey)) {
						$payment->taxes[$tax->tax_namekey] = clone($tax);
						$payment->taxes[$tax->tax_namekey]->tax_amount = $payment->payment_price_with_tax - $payment->payment_price;
						$payment->taxes[$tax->tax_namekey]->amount = $payment->payment_price;
					}
in there and it should work fine.

Please Log in or Create an account to join the conversation.

  • Posts: 323
  • Thank you received: 18
  • Hikashop Business
4 years 2 weeks ago #327121

Ok that code solved first problem, but now another
PHP Warning: Invalid argument supplied for foreach() in administrator/components/com_hikashop/classes/cart.php on line 2630

Form line 2629 (after code update) I have

$cart = $this->get($cart_id);
			foreach($cart->cart_products as &$cart_product) {
				if($cart_product->cart_product_quantity == 0 || (is_string($cart_product->cart_product_id) && substr($cart_product->cart_product_id, 0, 1) == 'p'))
					continue;
				if(!$this->compareCartProducts($p, $cart_product, null, $fields))
					continue;
				$p['id'] = (int)$cart_product->cart_product_id;
				$cart_products = array($p);
				return $this->updateProduct($cart_id, $cart_products);
			}
			return $this->addProduct($cart_id, $data);
		}

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
4 years 2 weeks ago #327151

Hi,

Ah yes, a check is missing there.
Change that whole code to:

$cart = $this->get($cart_id);
if(!empty($cart->cart_products)) {
			foreach($cart->cart_products as &$cart_product) {
				if($cart_product->cart_product_quantity == 0 || (is_string($cart_product->cart_product_id) && substr($cart_product->cart_product_id, 0, 1) == 'p'))
					continue;
				if(!$this->compareCartProducts($p, $cart_product, null, $fields))
					continue;
				$p['id'] = (int)$cart_product->cart_product_id;
				$cart_products = array($p);
				return $this->updateProduct($cart_id, $cart_products);
			}
}
			return $this->addProduct($cart_id, $data);
		}
and it will remove that warning.

Please Log in or Create an account to join the conversation.

  • Posts: 323
  • Thank you received: 18
  • Hikashop Business
4 years 2 weeks ago #327174

Solved. No warning any more. Thank you.

I have one other, but is about os map plugin.
PHP Warning: Parameter 1 to xmap_com_hikashop::getTree() expected to be a reference, value given in administrator/components/com_osmap/library/alledia/osmap/Helper/General.php on line 396

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
4 years 2 weeks ago #327177

Hi,

You can edit the file plugins/xmap/com_hikashop/com_hikashop.php and change the line:
function getTree( &$xmap, &$parent, &$params ){
to:
function getTree( $xmap, &$parent, &$params ){
and it should fix the problem.

Please Log in or Create an account to join the conversation.

  • Posts: 323
  • Thank you received: 18
  • Hikashop Business
4 years 1 week ago #327356

Solved this to.
Thank you nicolas

Please Log in or Create an account to join the conversation.

Time to create page: 0.051 seconds
Powered by Kunena Forum