I’ll try to provide as much context as possible.
Been trying to override Mage_GoogleShopping_Model_Attribute_Link for 2 days now but I’m unable to get Magento to pickup my version of the file.
Mage_GoogleShopping_Model_Attribute_Link class is in app/code/core/Mage/GoogleShopping/Model/Attribute/Link.php
I put my class Safoo_Froogle_GoogleShopping_Model_Attribute_Link in /app/code/local/Safoo/Froogle/GoogleShopping/Model/Attribute/Link.php
Then my config.xml:
<global>
...
<models>
<safoofroogle>
<class>Safoo_Froogle_Model</class>
</safoofroogle>
<googleshopping>
<rewrite>
<attribute_link>Safoo_Froogle_GoogleShopping_Model_Attribute_Link</attribute_link>
</rewrite>
</googleshopping>
</models>
<helpers>
<googleshopping>
<rewrite>
<price>Safoo_Froogle_GoogleShopping_Helper_Price</price>
</rewrite>
</googleshopping>
</helpers>
(Note the Helper Rewrite above works perfectly.)
I debugged the call to the Link model in Mage_GoogleShopping_Model_Type::_createAttribute
protected function _createAttribute($name)
{
$modelName = 'googleshopping/attribute_' . $this->_prepareModelName($name);
$useDefault = false;
###LOGGING###
Mage::log($modelName);
Mage::log(get_class(Mage::getModel($modelName) ));
###LOGGING###
try {
$attributeModel = Mage::getModel($modelName);
$useDefault = !$attributeModel;
} catch (Exception $e) {
$useDefault = true;
}
if ($useDefault) {
$attributeModel = Mage::getModel('googleshopping/attribute_default');
}
$attributeModel->setName($name);
return $attributeModel;
}
And this is the result of the 2 log statements:
2011-11-01T06:57:17+00:00 DEBUG (7): googleshopping/attribute_Link
2011-11-01T06:57:17+00:00 DEBUG (7): Mage_GoogleShopping_Model_Attribute_Link
So Mage::getModel('googleshopping/attribute_Link') is still fetching Mage_GoogleShopping_Model_Attribute_Link.
The only way I’ve been able to override the class is to copy the Link.php file into the corresponding local directory: app/code/local/Mage/GoogleShopping/Model/Attribute/Link.php but wanted to avoid that.
Just not working. My Helper Overload works. And I thought I should be able to override this class just like shown here:
http://www.magentocommerce.com/boards/viewthread/222046
http://www.magentocommerce.com/boards/viewthread/35787/
Any ideas?
You’ve uncovered a bug in the
Mage_GoogleShopping_Model_Typeclass that’s preventing your rewrite from being applied. Based on your debugging, here’s the code that eventually gets called to instantiate a modelAlthough it’s not enforced everywhere in code, it’s a well established guideline that all class aliases (
'googleshopping/attribute_Link'is a class alias) should be lowercase. Because of the capital letter L inattribute_Link, when Magento looks for the class name to use in a rewrite, it searches for a node named with a capital L.Fortunately, you can work around this. Just make your
config.xmlrewrite section look like this, and your rewrite should workThis way you’ll catch instantiations in the form
Mage::getModel('googleshopping/attribute_Link')AND in the formMage::getModel('googleshopping/attribute_link').For future reference, when you’re debugging rewrites, the
method in
is where Magento does its lookup for class rewrites.