Showing posts with label shopping. Show all posts
Showing posts with label shopping. Show all posts

Tuesday, September 20, 2011

How to remove an item from magento shopping cart automatically?

$cartHelper = Mage::helper('checkout/cart');
$items = $cartHelper->getCart()->getItems();
foreach ($items as $item) {
    if ($item->getProduct()->getId() == $productId) {
        $itemId = $item->getItemId();
        $cartHelper->getCart()->removeItem($itemId)->save();
        break;
    }
} 
Note:
The ItemId (ID of an item in the cart) is not the same as the ProductId of the product it represents. Try iterating through the items in the cart until you find the one with the ProductId you want to remove.

How to hide shopping cart sidebar when it is empty?

Displaying the shopping cart when the user has nothing in it is not necessary. To hide the cart in the sidebar, try the following steps.
Step 1: Edit your "/template/checkout/cart/sidebar.phtml" and look for line
<div class="box base-mini mini-cart"> 
Step 2: Add these lines before the opening div tag
<?php $_cartQty1 = $this->getSummaryCount() ?>
<?php if ($_cartQty1 >0): ?>
Step 3: Add this line to the bottom of the file
<?php endif ?> 
Thats it. You are done.