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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary 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

Post by kec » Mon Jul 24, 2023 3:21 am

Unfortunately not working with 3.0.3.8. It's not auto-updating after placing a product in the basket.

kec
New member

Posts

Joined
Sat Apr 20, 2013 6:06 pm

Post by straightlight » Mon Jul 24, 2023 5:25 am

kec wrote:
Mon Jul 24, 2023 3:21 am
Unfortunately not working with 3.0.3.8. It's not auto-updating after placing a product in the basket.
Which OC v3.0.3.8 are you referring to?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by kec » Mon Jul 24, 2023 5:40 am

The standard OC 3.0.3.8. :)

What i did (for) now is removing the "shopping cart" in the header (header.twig) and replaced it with the {{ cart }}. Now it's auto-updating itself. Next bump is to change the dropdown-cart that is connected with the {{ cart }} to the checkout-page directly.

kec
New member

Posts

Joined
Sat Apr 20, 2013 6:06 pm

Post by paulfeakins » Mon Jul 24, 2023 6:19 pm

straightlight wrote:
Mon Jul 24, 2023 5:25 am
Which OC v3.0.3.8 are you referring to?
I've told you before - there are not different versions of a specific version, please try and understand this.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by straightlight » Mon Jul 24, 2023 8:44 pm

paulfeakins wrote:
Mon Jul 24, 2023 6:19 pm
straightlight wrote:
Mon Jul 24, 2023 5:25 am
Which OC v3.0.3.8 are you referring to?
I've told you before - there are not different versions of a specific version, please try and understand this.
https://github.com/opencart/opencart/bl ... dex.php#L3

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Users browsing this forum: paulfeakins and 417 guests