2

When user leaves checkout funnel I need to logout him while preserving his cart contents (so the just logged out user as a guest would see all cart items that he had in a cart when he was logged in). How can I achieve that?

2
  • what is mean by " logout him while preserving his cart contents"?
    – Amit Bera
    Feb 12, 2015 at 12:33
  • So all items that were in cart when he was loggen in remains there after logout (for guest user)
    – breethe
    Feb 12, 2015 at 13:04

2 Answers 2

1

The Mage_Checkout module declares an observer on customer_logout event which executes the Mage_Checkout_Model_Observer::unsetAll() method which in turn calls Mage_Checkout_Model_Session::unsetAll() whose body follows:

public function unsetAll()
{
    parent::unsetAll();
    $this->_quote = null;
}

As you see, it is responsible for clearing all data from session, including the quote.

You could be tempted to disable the event observer but I discourage it because it is necessary to clear private data from session.

A better approach could be that of registering your own observer on the same event and call the preserveQuote() method which copies the quote of the logging-out customer to the already emptied (by the core observer) session as show below:

public function preserveQuote($observer)
{
    $customerQuote = Mage::getModel('sales/quote')->loadByCustomer($observer->getCustomer());
    $currentQuote = Mage::getSingleton('checkout/session')->getQuote();
    $currentQuote->merge($customerQuote);
}

Do your tests because I didn't examine if there can be drawbacks to this solution.

Hope it helps.

0

Under system > configuration > customers > persistent shopping cart you can enable the persistent shopping cart feature, and make your settings accordingly for how long to keep items in the customer's cart.

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.