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..
Yes. You can write plugins for abstract classes and plugins should always be preferred over preferences if possible. Preferences are useful if you want to replace an implementation.
A subclass must override all abstract methods of an abstract class. However, if the subclass is declared abstract, it's not mandatory to override abstract methods.
Abstract methods cannot be overridden by a concrete subclass.
You have to put the path of the class override the target class in the "type" attribute and set sortOrder for you plugin. Magento 2 will run your plugin based on sortOrder. We will use After listener Plugin for example. You have to pay attention to your plugin class, it does not extend the class you want to override.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With