Clear abandoned cart items during login in Magento

You may have noticed that old cart items (abandoned) get merged with the current one when the customer tries to log in.
It’s good in terms of sales but sometimes your merchant simply may not want this feature.
In this case, we can easily clear the abandoned cart items and stop being merged with the current cart with the following steps:

Step 1. Hooking into the event: load_customer_quote_before
Add the following code in the file app/code/local/MagePsycho/Module/etc/config.xml


Step 2. Implementing logic in observer method
Add the following code in the file app/code/local/MagePsycho/Module/Model/Observer.php

class MagePsycho_Module_Model_Observer
	public function clearAbandonedCarts(Varien_Event_Observer $observer)
		$lastQuoteId = Mage::getSingleton('checkout/session')->getQuoteId();
        if ($lastQuoteId) {
            $customerQuote = Mage::getModel('sales/quote')

        } else {
            $quote = Mage::getModel('checkout/session')->getQuote();

	protected function _removeAllItems($quote){
        foreach ($quote->getAllItems() as $item) {
            if ($item->getHasChildren()) {
				foreach ($item->getChildren() as $child) {

That’s it.

Now you can download this trick as a Magento Module from [here]

Happy Coding!