1

I am trying to programatically clear a product's group prices within a custom module. Thisi s my code:

Mage::setIsDeveloperMode(true); // for debug only
try
{
    $product = Mage::getModel('catalog/product')->load($productId);
    $product->setGroupPrice(null);
    $product->save();
}
catch (Exception $ex)
{
    echo "Error: ". $ex->getMessage();
}

When this code executes, I get the following exception:

Warning: Invalid argument supplied for foreach() in /home/www-data/public_html/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 1180

In the system.log file, I see allot of these entries:

2016-03-17T18:01:06+00:00 ERR (3): Warning: Invalid argument supplied for foreach() in /home/www-data/public_html/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 1180 2016-03-17T18:01:06+00:00 ERR (3): Recoverable Error: Argument 3 passed to Mage_Catalog_Model_Resource_Abstract::_canUpdateAttribute() must be of the type array, null given, called in /home/www-data/public_html/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 1225 and defined in /home/www-data/public_html/app/code/core/Mage/Catalog/Model/Resource/Abstract.php on line 543 2016-03-17T18:01:06+00:00 ERR (3): Recoverable Error: Argument 3 passed to Mage_Eav_Model_Entity_Abstract::_canUpdateAttribute() must be of the type array, null given, called in /home/www-data/public_html/app/code/core/Mage/Catalog/Model/Resource/Abstract.php on line 545 and defined in /home/www-data/public_html/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 1254 2016-03-17T18:01:06+00:00 ERR (3): Warning: array_key_exists() expects parameter 2 to be array, null given in /home/www-data/public_html/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 1256

Any idea what might be causing this? The same code on my dev magento setup works, but in production magento, this error started to appear, so I am a little confused.

13

You've probably have solved this problem already, but for other people looking for resolution - you need to set store scope first.

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
  • 1
    Thanks, that worked perfectly. Do you have any idea why you need to set the store ID manually? Also, it's a bit weird that the error message isn't quite helpful... – Niels Jul 3 '17 at 9:50
  • Why need to set admin store id when product save from frontend – Pradip Garchar Apr 26 '18 at 7:31

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.