Customer visit website and add the product,

then customer login.

if customer already have cart items, its removed old items, newly added items only showing


Customer already have 5 products in cart > Visit the site > add newly 2 products in cart > login customer account > show the cart newly add 2 product (old cart products are removed)

Any suggestions will be appreciated.

2 Answers 2


use this event sales_quote_merge_before

put this in config.xml

   <sales_quote_merge_before><!--calling this event before merging the old cart with newly added cart items while login--> 
            <ws_clearoldcartproducts_observer><!--unique identifier name for our observer--> 
                <class>Ws_Clearoldcartproducts_Model_Observer</class><!--Our observer class name--> 
                <method>loadCustomerQuote</method><!--Method to be called from our observer class--> 

put this in observer.php

public function loadCustomerQuote() 
    $customerQuote = Mage::getModel('sales/quote') 
    if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId()) 
        // Removing old cart items of the customer. 
        foreach ($customerQuote->getAllItems() as $item) 
            if ($item->getHasChildren()) { 
                foreach ($item->getChildren() as $child) { 
        $this->getQuote()->setCustomer(Mage::getSingleton('customer/session')->getCustomer()) ->setTotalsCollectedFlag(false) ->collectTotals() ->save();
    return $this; 

Refer this link

  • i got the answer from the link. thanks @surya
    – VijayS91
    May 15, 2014 at 13:28

I suggest you hook onto the event called sales_quote_merge_before and empty one of the cart (the existing one for example).
This event is triggered after login and before sales_quote_collect_totals_before

  • were you able to achieve what you wanted this way? or does it not quite intervene where you'd like it to. May 14, 2014 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.