How to remove item from quote in Magento?

magento, magento-1.4

Solution

Try

$cartHelper = Mage::helper('checkout/cart');
$items = $cartHelper->getCart()->getItems();        
foreach ($items as $item) 
{
   $itemId = $item->getItemId();
   $cartHelper->getCart()->removeItem($itemId)->save();
} 

See http://www.magentocommerce.com/boards/viewthread/30113/

Problem

During the checkout process I sometimes want to programmatically remove items from the session's quote. So I tried this code: ``` $quote = Mage::getSingleton('checkout/session')->getQuote(); $all_quote_items = $quote->getAllItems(); foreach ($all_quote_items as $item) { $quote->removeItem($item->getId())->save(); } ``` However, after this loop the list of items in the `$quote` object is still the same, i.e. no items have been removed. Any ideas what I am missing here? Using Magento 1.4.1.1

Original source