Cart behavior on Login in Magento

Published On: 24 December 2011.By .
  • Digital Engineering

While customizing Magento cart, if you are using quote id and item ids of cart in any reference then you must face a problem with login.

If you have some thing in cart and guess your cart id or quote id is 41 and you log in at any step the cart id will get changed and the cart or quote history with id 41 will be deleted permanently and same will happen with the item ids. This happens because magento changes the quote when you are log in.

The new cart or quote id will be generated in two ways. If the logged in user has previously (before you logged out last time) stored items in his cart and that cart’s id is suppose 26 than the new items will be added into that cart or quote and current cart id will be changed to 26. But if you don’t have any thing previously than a new cart or quote id will be generated as suppose 42 and cart item ids will be changed accordingly.

magento tips

magento tips

If you don’t want the things to happen like this and want to change the behavior that it should not change the cart id and its item ids if those created while the user was not logged in then you need to make a change in/app/code/core/mage/Checkout/Model/Observer.php file.

You need to change the function loadCustomerQuote with this –

 

public function loadCustomerQuote()

{

try

{

if(Mage::getSingleton(‘checkout/session’)->getQuote()->getItemsCount() > 0)

{

}

else

{

Mage::getSingleton(‘checkout/session’)->loadCustomerQuote();

}

}

catch (Mage_Core_Exception $e) {

Mage::getSingleton(‘checkout/session’)->addError($e->getMessage());

}

catch (Exception $e) {

Mage::getSingleton(‘checkout/session’)->addException(

$e,

Mage::helper(‘checkout’)->__(‘Load customer quote error’)

);

}

}

Related content

That’s all for this blog

Go to Top