I'm working on a site where we have two types of customers, agents and sites. A customer logs on as an agent then chooses a site that they can order for (these are in a custom customer attribute). The agent customer adds items to the site customer basket and can check out (the site user selection actually changes the customer session from being the agent customer to the site customer).

Now, if the agent customer has items in their basket and then changes the site customer we want to keep the basket contents intact but because they are in reality changing the logged on customer from one site customer to another the basket contents are lost. Anyone have any ideas on how I can keep the basket contents intact between site customers?

  • Why not change the customer_id of the quote, when the customer changes? Commented Mar 6, 2013 at 10:51

3 Answers 3


Changing the customer_id of the quote:

  • The problem I can see with that is that the quote also stores things like the customer email etc in it so there is a strong possibility of data integrity issues. I'll certainly give it a go though and see what happens. Commented Mar 6, 2013 at 11:21
  • 1
    Actually, that does seem to work thanks Fabian. I just grab the quoteID and then use this after the new customer has been logged in and assign the cart to them, The basket is then intact and ready for checkout for the new site customer. One small change was that it shoud have been Mage::getModel('sales/quote') not checkout/quote but apart from that it seems to work perfectly. Commented Mar 6, 2013 at 13:00
  • Hi Fabian How to achieve same on Magento 2?? can you please help? Commented Dec 9, 2016 at 12:18
  • I think this has some race conditions, when both customers are accessing it at the same time. @aton1004 no clue, ask another question for M2 Commented Dec 11, 2016 at 16:53

No experience with this what so ever and this code is far from tested OR complete but you can probably use an event observer (not checkout_cart_product_add_after or you'll have yourself an infinite add loop) that is triggered when adding the product and then execute something like this

$customer_session = Mage::getSingleton('customer/session')->setCustomer([customerid]);
$cart_session = Mage::getSingleton('checkout/session')->loadCustomerQuote();

$cart = Mage::getSingleton('checkout/cart’'); 

$product = Mage::getSingleton('catalog/product')->load($productId); 

$cart->addProduct($product, array('qty' => $qty)); 

  • If you manage to get it working please share it, it's actually quite an interesting case. Commented Mar 6, 2013 at 9:52
  • Thanks Sander, I'll have a play around with it and see how that works and I'll share the finished solution (if it all works). Commented Mar 6, 2013 at 10:12
  • Great, let me know if you need any help if you run into an issue Commented Mar 6, 2013 at 10:18

@'Fabian Blechschmidt' for the answer for Sharing the shopping cart. I have tried your code, but need some modifications in it, it should use 'sales/quote' instead of 'checkout/quote', after that it is working fine for me. I have used below code:


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.