One of the last things I had to implement in Magento was a function to empty the customer cart. At first I found this great extension made by the Inchoo people, but it did much more than I needed. Having a controller to do this is fair enough, and the only code you need to put in that controller is the following:

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

$quote->delete();
Categories: Getting things

3 Comments

Magento Development India · July 22, 2012 at 7:32 pm

I had this query a few days ago but I found one plugin. Thanks for this article. I was looking for it.

doh · January 29, 2013 at 11:45 am

This gives me:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`magento`.`sales_flat_quote_item`, CONSTRAINT `FK_SALES_FLAT_QUOTE_ITEM_QUOTE_ID_SALES_FLAT_QUOTE_ENTITY_ID` FOREIGN KEY (`quote_id`) REFERENCES `sales_flat_quote` (`entity_id`) ON DELETE CASC)

    Pau · January 29, 2013 at 12:21 pm

    Hi doh,

    I’m not sure why that constraint is affecting. It shouldn’t. Does this happen to you for all the quotes or only for a particular one?

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Press Ctrl+C to copy the following code.
"