List cart items on all pages

  • Posts: 97
  • Thank you received: 0
8 years 7 months ago #252708

-- HikaShop version -- : 2.6.0

I need on all pages pages this code, this are simple all products in cart:

$this->setLayout('listing_price');

					$k = 0;
					$group = $this->config->get('group_options',0);
					$defaultParams = $this->config->get('default_params');
					$productClass = hikashop_get('class.product');
					$quantityDisplayType = hikashop_get('type.quantitydisplay');

					foreach($this->rows as $i => $row){
						if(empty($row->cart_product_quantity)) continue;
						if($group && $row->cart_product_option_parent_id) continue;
						$productClass->addAlias($row);
						?>
        {
          'name': '<?php echo strip_tags($row->product_name); ?>',
          'id': '<?php echo $row->product_id; ?>',
          <?php
            $this->row=&$row;
            $this->unit=false;
            ?>
          'price': '<?php echo preg_replace('/\s+/', '', strip_tags($this->loadTemplate())); ?>',
          'brand': 'my_brand',
          'category': '',
          'variant': '-',
          'quantity': <?php echo $row->cart_product_quantity; ?>
       }<?php if ($row != end($this->rows)) : ?>,<?php endif; ?>
						<?php
						$k = 1-$k;
					}

But on some pages I get this error : Notice: Undefined property: CheckoutViewCheckout::$rows in PATH_TO_TEMPLATE\html\com_hikashop\checkout\step.php on line 207

What do I have to fix there to get always correct cart products?

Last edit: 8 years 7 months ago by shpuser.

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

  • Posts: 83933
  • Thank you received: 13588
  • MODERATOR
8 years 7 months ago #252755

Hi,

That code would only work when $this->rows is initialized with the listing of products of the cart and that's only the case for some of the views of the checkout.
So you need to check if it's set before and if not, you need to load it yourself like that:

if(!isset($this->rows)){
$cartClass = hikashop_get('class.cart');
$cart = $cartClass->loadFullCart();
$this->rows =& $cart->products;
 }
www.hikashop.com/support/documentation/6...umentation.html#code

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

Time to create page: 0.061 seconds
Powered by Kunena Forum