3/09/2011

How to Remove Product from cart on checkout page or by coding in magento

From magento cart you can delete product by clicking on delete button from cart page , but if you wish to delete any cart item in checkout page or by coding then you have write

$session= Mage::getSingleton('checkout/session');
$quote = $session->getQuote();

$cart = Mage::getModel('checkout/cart');
$cartItems = $cart->getItems();
foreach ($cartItems as $item)
{
    $quote->removeItem($item->getId())->save();
}

By writing the above code your all cart item will be delete.If you wish to delete a particular product from the cart session then instead of writing $item->getId() pass your Id of the product.

e.g: - foreach ($cartItems as $item)
{
    if($item->getId()== 2)
    {
        $quote->removeItem($item->getId())->save();
    }
}

3 comments:

  1. thanks..it helps me..:)

    ReplyDelete
  2. i which flie i use this code. i want check box option in cart page in magento tell me

    ReplyDelete
  3. Where we want to Paste this code can you please tell me anyone

    ReplyDelete