Fatal error: Call to a member function setAttribute() on a non-object in Magento
After upgrading with latest magento version, I came across with the following error when I opened my product to edit or even add new product from scratch. I was also unable to search any product/item on my store. Here is the error what I got:
Fatal error: Call to a member function setAttribute() on a non-object in E:\wamp\www\upgrade\app\code\core\Mage\Eav\Model\Entity\Attribute\Abstract.php
After a long time fighting with magento pawn I came through with following solution.
On /app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php
Line around 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);
}
And open file: /app/code/core/Mage/Adminhtml/Block/Widget/Form.php
Line around 201/202:
Find:
$element->setValues($attribute->getSource()->getAllOptions(true, true));
Replace with:
if(is_object($attribute->getSource())){
$element->setValues($attribute->getSource()->getAllOptions(true, true));
}
And open file: /app/code/core/Mage/Eav/Model/Entity/Attribute/Frontend/Abstract.php
Line around 142/144:
Find:
return $this->getAttribute()->getSource()->getAllOptions();
Replace with:
if(is_object($this->getAttribute()->getSource())){
return $this->getAttribute()->getSource()->getAllOptions();
}
Cheer up all done.
|