Thứ Ba, 8 tháng 3, 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();

    }

}

Không có nhận xét nào:

Đăng nhận xét