A place to log my programming solutions.
8
Sep 09

Magento Clear Shopping Cart and Session

If you ever need to programmatically clear Magento’s shopping cart, use the snippet of code below. If you need to clear the user’s entire session, including the shopping cart, shipping information, billing information and chosen payment methods, please refer to the snippet further below.

Clear shopping cart

foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ){
    Mage::getSingleton('checkout/cart')->removeItem( $item->getId() )->save();
}

Clear entire session

Mage::getSingleton(‘checkout/session’)->clear();

Happy coding!

  • StumbleUpon
  • Digg

Responses

  1. “Clear shopping cart” works perfectly.
    Thx!

  2. Chris

    What page should we update in order to get this working correctly? I figured out how to do it by modifying core code but was thinking someone was able to do it by modifying a design file.

  3. Atomschinken

    Shouldn’t do “Mage::getSingleton(‘checkout/cart’)->truncate();”

    the same?

Leave a Response

About NVNCBL and Myself

Contact Me