Like most Magento related issues, banging your head against the wall is often necessary to find a solution. This time however, nothing.

I am having a strange issue for customers who are logged out and trying to add items to an empty cart. It won't work for some specific product types.

I have extended the Cart Controller to add support for user inputted values instead of the standard Magento dropdown approach. This means that users could potentially input a number that doesn't yet exist yet as an associated product to my configurable (see image below).

enter image description here

Therefore I have implemented a system that will create the product should it not exist, then add it to the basket. This works beautifully for logged in users (and even logged out users with existing items in the basket). But it doesn't work when a logged out user has an empty cart despite it adding the success message.

My initial thought was that it was a Session related issue because users without accounts don't access the database, and also because it randomly starts working once a logged out user has items existing in the basket.

I have attempted refreshing sessions, initialising the cart, adding it twice for good measure but still nothing.

1 Answer 1


Thanks to Bezzie It turned out to be an emulation problem. I never knew such a thing existed. Whenever you need to do admin functionality outside the admin you must set the current store as "admin". Emulation was introduced in Magento 1.5 for this reason. Source here.

$appEmulation = Mage::getSingleton('core/app_emulation');

//Start environment emulation of the specified store
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation(Mage_Core_Model_App::ADMIN_STORE_ID);

 * Any code thrown here will be executed as we are currently running that store
 * with applied locale, design and similar

//Stop environment emulation and restore original store

It seems obvious when you look at it, but figuring this one out was mad! Thanks Bezzie

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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