I'm adding products to the cart using an ajax call. Inside the ajax responder I have the initial code.

Mage::getSingleton('core/session', ['name' => 'frontend']);

If a user is not logged in it adds the products to the cart with no problems, but if a user is logged in, the second line causes the user to log out. Leaving the store in a logged out state with the last product added to the cart. Do I need to do anything to preserve the users session?

  • Is this code outside of the scope of Magento application ?
    – Prateek
    Dec 8 '15 at 14:08
  • Yes, it's a single php file acting as an ajax responder. That's why I'm initializing the Magento application to access events, sessions etc. I was using Mage::init() first, but that didn't give me access to events.
    – TheCokeGuy
    Dec 8 '15 at 14:15
  • Take a look at the method preDispatch inside Mage_Core_Controller_Varien_Action class. That is how Magento initializes the sessions. You might need to do the same somehow.
    – Prateek
    Dec 8 '15 at 14:37

I found out the described behavior can happen if there's sessions from unstable code. After clearing the browser cache it works perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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