When saving products in magento through custom scripts I have always had to add the following:


Otherwise you get a wierd error from eav/config model about an invalid argument foreach.

Can anyone explain why products can only be saved under the admin store id? and if this code i have been using is in fact the best way to deal with it?

1 Answer 1


When saving a product the call stack reaches Mage_Eav_Model_Entity_Abstract::_collectSaveData(). In this method you loop through the _origData member of the model and get the attributes that are different and save only those ones.
The _origData member is populated when loading a model by calling setOrigData().
So far so good. The difference is that for the product model the method setOrigData() looks like this (for performance reasons I assume):

public function setOrigData($key=null, $data=null)
    if (Mage::app()->getStore()->isAdmin()) {
        return parent::setOrigData($key, $data);

    return $this;

This means that if you are not in the admin environment _origData will be null.
In this case _collectSaveData() tries to loop through null, thus the error you are getting.

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.