Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop Magento merging the basket on login?

Tags:

magento

If you were to login to Magento and add some products to your basket and then leave the site, these are saved for the next time you return to the site.

This, however, causes an issue when you do return. If, on your return, you added a product to your basket without logging in and then logged in at the start of the checkout process, your guest and saved basket will be merged. This is undesirable.

Is there any way to make Magento clear the saved basket on login if your current basket has items in it?

like image 516
Phil Lavin Avatar asked Apr 12 '11 15:04

Phil Lavin


1 Answers

It looks like the code that governs this is in Mage_Checkout_Model_Session, specifically where it calls Mage_Sales_Model_Quote::merge. This means that you have a few options.

  1. Override the session class and force it not to cause the merge.
  2. Override the quote class and cause it never to merge carts. There may be secondary bugs to this approach if other parts of the system also attempt to merge carts.
  3. Hook into the event that quote calls (sales_quote_merge_before) and use that opportunity to empty one of the carts. You would have to detect around when this should be done, but it is by far cleaner than the other two.
like image 184
Joe Mastey Avatar answered Nov 15 '22 19:11

Joe Mastey