Michael
Michael

Reputation: 4876

Override/Extend Magento Abstract class?

I only need to add a method to the Mage_Core_Model_Abstract class.

For that, in my config.php I have

<models>
     <mymodule>
         <class>Mynamespace_Mymodule_Model</class>
     </mymodule>
     <core>
         <rewrite>
             <mage_core_model_abstract>Mynamespace_Mymodule_Model_Abstract</mage_core_model_abstract>
         </rewrite>
     </core>
</models>

It doesn't really work..

I know that there is a way of "overriding" by copying all the folder structure including the class file into my module, but I would like to know if there is a way to make it more fancy, within my module - something similar as above..

Upvotes: 8

Views: 9180

Answers (1)

Nick
Nick

Reputation: 6965

You can only rewrite classes that you instantiate directly, from config.xml.

The various values in config.xml are used when creating an object through a factory (e.g. Mage::getModel($class), Mage::getSingleton($class), Mage::helper($class), etc). The value of the $class argument is used to translate catalog/product into Mage_Catalog_Model_Product.

This means it's impossible to rewrite (in the Magento sense) classes that are used as superclasses, including abstract classes (by definition).

If you want to redefine any class that's used as a superclass, then you'll need to place a file in the correct place further up the include path. In this case, you'd need to make a file in app/code/local/Mage/Core/Model/Abstract.php.

Upvotes: 13

Related Questions