Post by SilverDinky » Tue Nov 21, 2017 1:32 am

Hi All,
I am just starting to get to grips with OC3 (the last OC site I did was way back in 1.5.6.4). I am trying to add the quantity of cart items to the cart link in the very topmost bar of the header. In header.twig I have tried inserting the following:

Code: Select all

{ $products = $this->cart->getProducts(); $data['total'] = count($products); }
inserted just before:

Code: Select all

{{ text_shopping_cart }}
so the line reads:

Code: Select all

<li><a href="{{ shopping_cart }}" title="{{ text_shopping_cart }}"><i class="fa fa-shopping-cart"></i><span class="hidden-xs hidden-sm hidden-md">&nbsp;{ $products = $this->cart->getProducts(); $data['total'] = count($products); }{{ text_shopping_cart }}</span></a></li>
but all I get is:

Code: Select all

 %s item(s) - %sShopping Cart 
displayed alongside the cart icon, what I would like is something like:

(3) Shopping Cart

I'd be grateful if someone could give me a nudge in the right direction please.

Thanks,
Paul.

Using OC 3.0.2.0
Site: http://freshmistletoe.co.uk

Newbie

Posts

Joined
Sun May 25, 2014 7:18 pm

Post by straightlight » Tue Nov 21, 2017 2:38 am

You cannot set PHP variables into TWIG files in OC v3.x releases:

Code: Select all

<li><a href="{{ shopping_cart }}" title="{{ text_shopping_cart }}"><i class="fa fa-shopping-cart"></i><span class="hidden-xs hidden-sm hidden-md">&nbsp;{ $products = $this->cart->getProducts(); $data['total'] = count($products); }{{ text_shopping_cart }}</span></a></li>
should read as something like:

Code: Select all

<li><a href="{{ shopping_cart }}" title="{{ text_shopping_cart }}"><i class="fa fa-shopping-cart"></i><span class="hidden-xs hidden-sm hidden-md">&nbsp;{{ text_shopping_cart }}</span></a></li>
Then, in your catalog/controller/common/header.php, you'd need to set something like:

Code: Select all

$data['text_shopping_cart'] = sprintf($this->language->get('text_shopping_cart'), $this->cart->countProducts());
In your catalog/language/<your_language_code>/common/header.php file,

find:

Code: Select all

$_['text_shopping_cart'] = 'Shopping Cart';
replace with:

Code: Select all

$_['text_shopping_cart'] = 'Shopping Cart (%s)';
This should rectify the problem.

The most generated errors being found on Opencart forum originates from contributed programming.

Regards,
Straightlight


Guru Member

Posts

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

Post by SilverDinky » Tue Nov 21, 2017 6:21 pm

That's great, many thanks for the help. I'll give it a try when I get to my desk and report back.

Newbie

Posts

Joined
Sun May 25, 2014 7:18 pm

Post by SilverDinky » Tue Nov 21, 2017 6:48 pm

Yep, just tried it and it works a charm. ;D

Thank you very much for your help, it's much appreciated.

Newbie

Posts

Joined
Sun May 25, 2014 7:18 pm
Who is online

Users browsing this forum: No registered users and 13 guests