Try the Demo

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
 Signature 

Xogenics gained Magento expertise by developing integrated shops with complex ERP systems. Now we’ve decided to share some of our frond-end developments with the community! Check out our FREE and commercial extensions on:
Xogenics.com

- Smarter Shipping Methods
- Recurring Sales
- Multiple Select Navigation
- Bundled Carrousels
- Clean Carts
- Hide Cart
- Stock Status Images

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top