Magento: Warning in Mage/Eav/Model/Entity/Abstract.php ?

Martin ZellerMagento 1 Comment

All you want to do is saving a product like this?
[php]$api = new Mage_Catalog_Model_Product_Api();
$productData = array();
$productData[‘visibility’] = Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE;
$productData[‘status’] = Mage_Catalog_Model_Product_Status::STATUS_DISABLED;
$api->update($product->getId(), $productData);[/php] Or maybe without the API?
[php]$product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
$product->setStatus(Mage_Catalog_Model_Product_Status::STATUS_DISABLED);
$product->save();[/php] And all you get is an error like this?
[text]Warning: Invalid argument supplied for foreach() in /opt/lampp/htdocs/whlid/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 972

#0 /opt/lampp/htdocs/whlid/app/code/core/Mage/Eav/Model/Entity/Abstract.php(972): mageCoreErrorHandler(2, ‘Invalid argumen…’, ‘/opt/lampp/htdo…’, 972, Array)
#1 /opt/lampp/htdocs/whlid/app/code/core/Mage/Eav/Model/Entity/Abstract.php(927): Mage_Eav_Model_Entity_Abstract->_collectSaveData(Object(Mage_Catalog_Model_Product))
#2 /opt/lampp/htdocs/whlid/app/code/core/Mage/Core/Model/Abstract.php(251): Mage_Eav_Model_Entity_Abstract->save(Object(Mage_Catalog_Model_Product))
#3 /opt/lampp/htdocs/whlid/app/code/core/Mage/Catalog/Model/Product/Api.php(219): Mage_Core_Model_Abstract->save()
#4 /opt/lampp/htdocs/whlid/app/code/local/Willhaben/Customer/controllers/AccountController.php(20): Mage_Catalog_Model_Product_Api->update(‘161’, Array)
#5 /opt/lampp/htdocs/whlid/app/code/core/Mage/Core/Controller/Varien/Action.php(376): Willhaben_Customer_AccountController->deleteanzeigeAction()
#6 /opt/lampp/htdocs/whlid/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(248): Mage_Core_Controller_Varien_Action->dispatch(‘deleteanzeige’)
#7 /opt/lampp/htdocs/whlid/app/code/core/Mage/Core/Controller/Varien/Front.php(158): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#8 /opt/lampp/htdocs/whlid/app/Mage.php(459): Mage_Core_Controller_Varien_Front->dispatch()
#9 /opt/lampp/htdocs/whlid/index.php(65): Mage::run()
#10 {main}[/text] The error occurs in this area of /app/code/core/Mage/Eav/Model/Entity/Abstract.php ?
[php]$origData = $this->_getOrigObject($newObject)->getOrigData();

/**
* drop attributes that are unknown in new data
* not needed after introduction of partial entity loading
*/
foreach ($origData as $k=>$v) {
if (!array_key_exists($k, $newData)) {
unset($origData[$k]);
}
}[/php] SOLUTION: try to prepend this line to your code:
[php]Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);[/php]

Comments 1

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.