Scenario:

While editing product programatically from frontend. I was trying to change the visibility of the product with the following code:

$_product = Mage::getModel('catalog/product')->load($product_id);
$_product->setData('visibility', '1');
$_product->save();

 

Problem:

Product could not be edited programatically from frontend. The following error message is shown:

Warning: Invalid argument supplied for foreach()  in  /var/www/magento/app/code/core/Mage/Eav/Model/Entity/Abstract.php on  line 937

Solution:

It seems that product updates are only made on the admin side and you have to change the store view while editing product from frontend.

Write the following before you edit product:

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
Hence, my new code will be :

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$_product->setData('visibility', '1');
$_product->save();

 Leave a Reply

(required)

(required)


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

   
© 2014 Developers Corner Suffusion theme by Sayontan Sinha