Post by Ljubo » Sat Jan 07, 2017 9:23 pm

Hi,
I want the cart in header to text some greeting message instead of message like 0 articles - 0 USD.
Off course, only if there are no items in the basket.

I did have it working in an earlier version of opencart (2.0.2.0) by modifying the file at:
... /catalogue/view/theme/default/template/common/cart.tpl
I did it by instead of:
<?php echo $text_items; ?>
I put:
<?php if ( ! $this->cart->hasProducts()) {
echo "SOME TEXT";
} else {
echo $text_items;
}
?>

Now, in version 2.3.0.2, the result is blank page and error logging:
PHP Fatal error: Call to a member function hasProducts() on null in ....

What is going on?

Active Member

Posts

Joined
Mon Jan 31, 2011 10:07 pm
Location - Serbia

Post by opencartmart » Sun Jan 08, 2017 12:10 am

In OC 2.3.x, $this->cart->hasProducts() is not accessible in the templates. Instead you can call that method in the cart controller and then assign return value to a variable and use that variable in the template file. So in the file catalog/controller/common/cart.php, add following:

Code: Select all

$data['hasProducts'] = $this->cart->hasProducts();
Now update template files as follows:

Code: Select all

<?php if ( ! $hasProducts) {
echo "SOME TEXT"; 
} else {
echo $text_items;
}
?>

XForm - Opencart Form Builder

Xshippingpro - An advanced Shipping Module


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am
Location - Dhaka, Bangladesh

Post by Ljubo » Sun Jan 08, 2017 2:17 am

Worked like a charm.

THANK YOU!


:)

Active Member

Posts

Joined
Mon Jan 31, 2011 10:07 pm
Location - Serbia

Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am
Location - Dhaka, Bangladesh
Who is online

Users browsing this forum: No registered users and 23 guests