Page 1 of 1
Hide empty cart in header
Posted: Thu Apr 11, 2019 11:12 pm
by waitz
Is there a way in OC 3 to empty the cart in the header when the cart is empty?
Re: Hide empty cart in header
Posted: Thu Apr 11, 2019 11:50 pm
by letxobnav
You mean a setting or via code?
Re: Hide empty cart in header
Posted: Fri Apr 12, 2019 12:27 am
by waitz
Any... I haven't found a setting so I was looking for an extension, or code if not possible
Re: Hide empty cart in header
Posted: Fri Apr 12, 2019 1:51 am
by letxobnav
file: catalog/controller/common/header.php
add:
Code: Select all
$data['cart_count'] = $this->cart->countProducts();
file: catalog/view/theme/default/template/common/header.twig
change:
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">{{ text_shopping_cart }}</span></a></li>
to:
Code: Select all
{% if cart_count > 0 %}
<li><a href="{{ shopping_cart }}" title="{{ text_shopping_cart }}"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md">{{ text_shopping_cart }}</span></a></li>
{% endif %}
This will not show the cart in the header if empty.
Re: Hide empty cart in header
Posted: Mon Apr 15, 2019 1:36 am
by waitz
Thank you :-)
Re: Hide empty cart in header
Posted: Mon Apr 15, 2019 5:17 am
by straightlight
Since this is about a true / false validation, there's no need for:
It could be changed to:
Re: Hide empty cart in header
Posted: Mon Apr 15, 2019 10:12 am
by letxobnav
true.
and you might consider hiding that icon dynamically when you are in the cart and empty it but that then has to be done with javascript in common.js.
I'll leave that to the jQuery experts.
Re: Hide empty cart in header
Posted: Mon Apr 15, 2019 10:23 am
by straightlight
It can also be done via CSS.
Re: Hide empty cart in header
Posted: Mon Apr 15, 2019 11:02 am
by letxobnav
I did not know that, how does css determine if the cart is empty?
Re: Hide empty cart in header
Posted: Mon Apr 15, 2019 6:16 pm
by straightlight
letxobnav wrote: ↑Mon Apr 15, 2019 11:02 am
I did not know that, how does css determine if the cart is empty?
By using the forum search. While this suggestion has been posted for the products total from the header:
viewtopic.php?f=202&t=210505&p=749185#p749146 , this CSS suggestion then came across:
viewtopic.php?f=202&t=210505&p=749185#p749185
Re: Hide empty cart in header
Posted: Mon Apr 15, 2019 6:33 pm
by letxobnav
yes, but that css trick hides the header icon regardless of whether there is content in the cart right?
I thought the idea was to hide it if empty but show it otherwise.
Re: Hide empty cart in header
Posted: Tue Apr 16, 2019 5:04 am
by straightlight
The CSS condition can be extended. It's just that the provided example shows the first portion but not the 2nd portion as you describe.