Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Hide cart on empty
 
seldon
Sr. Member
 
Total Posts:  92
Joined:  2007-11-08
 

Hi I would like my cart to be hidden when its empty. Now I know that there is the on empty switch option in the main.xml, but i in fact need to set a specific class on my html body (cause not only the cart must dissapear, but the entire column and the main column’s right margin must be removed). My question is, how would i implement this? Help is really appreciated! (I guess i must extend the html helper class somehow?)

 
Magento Community Magento Community
Magento Community
Magento Community
 
seldon
Sr. Member
 
Total Posts:  92
Joined:  2007-11-08
 

Ok, i figured this out, i think. I override the Mage_Page_Block_Html with my own class, which contains the method hasEmptyCart():

class Mage_MelrowPage_Block_Html extends Mage_Page_Block_Html {

        
public function hasEmptyCart(){
             
return $this->helper('checkout/cart')->getCount() == 0;
        
}        
        
    }

Then i added in my page template, a condition in which this method is called:

<body <?if ($this->hasEmptyCart()):?>class="no-cart"<?endif?>>

If anyone thinks i should do this differently, please let me know! Is it perhaps nicer to move the hasEmptyCart function code to a helper?

 
Magento Community Magento Community
Magento Community
Magento Community
 
xogenics
Member
 
Avatar
Total Posts:  35
Joined:  2011-10-17
Netherlands
 

You can use our free extension Hide Cart that enables users to hide the shopping cart block in case the cart is empty. You may also choose to hide the shopping cart block completely.

Image Attachments
hide-cart_03.png
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top