Magento : Fixed: Fatal error: Call to a member function setAttribute() on a non-object

1
158
views
After a recent Magento migration (using 1.4.1.1) I came across this error when trying to manage / create a new product. Later I also discovered the websites search function was also throwing a very similar error.
The error message detailed in the domains error_log file looked like this…

Error :
[error] [client 12.34.567.890] PHP Fatal error:  Call to a member function setAttribute() on a non-object in /path/to/your/domain.co.uk/httpdocs/app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php on line 374, referer: http://Yourdomain.com/index.php/admin/catalog_product/index/key/.../

Solutions :
In /app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php
Aprox line 374, find:

$this->_source = Mage::getModel($this->getSourceModel())
->setAttribute($this);
Replace with:

if(is_object(Mage::getModel($this->getSourceModel()))) {
$this->_source = Mage::getModel($this->getSourceModel())
->setAttribute($this);
}
In /app/code/core/Mage/Adminhtml/Block/Widget/Form.php
Aprox line 201, find:

$element->setValues($attribute->getSource()->getAllOptions(true, true));
Replace with:

if(is_object($attribute->getSource())) {
$element->setValues($attribute->getSource()->getAllOptions(true, true));
}
In /app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Abstract.php
Aprox line 142, find:

return $this->getAttribute()->getSource()->getAllOptions();
Replace with:

if(is_object($this->getAttribute()->getSource())) {
return $this->getAttribute()->getSource()->getAllOptions();
}
With those 3 changes you should be good to go (maybe refresh your Cache for good practice).
chances are we’ll be able to help out!
Tested on Magento version 1.4.1.1, feel free to leave a comment if this helps you out.

1 COMMENT