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

piaoling  2011-07-14 18:24:43

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();
    }
}

from:https://aniscartujo.com/webproxy/default.aspx?prx=http://xhtmlandcsshelp.blogspot.com/search/label/Magento

类别 :  magento(258)  |  浏览(3202)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: