I am trying to override an abstract in Magento but it does not like the info in my config.xml below you will see my folder structure for the abstract I am trying to override and the portion of my config.xml specific to this file.
Original Directory:
app/code/core/Mage/Rule/Model/Abstract.php
My Directory:
app/code/local/EGeeked/Coupons/Rule/Model/Abstract.php
My config.xml:
<models>
<EGeeked_Coupons>
<class>EGeeked_Coupons_Rule_Model_Abstract</class>
</EGeeked_Coupons>
<rule>
<rewrite>
<model_abstract>EGeeked_Coupons_Rule_Model_Abstract</model_abstract>
</rewrite>
</rule>
</models>
My extends in the Abstract.php
abstract class EGeeked_Coupons_Rule_Model_Abstract extends Mage_Core_Model_Abstract
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.
you can override both abstract and normal methods inside an abstract class. only methods declared as final cannot be overridden.
If you declare a method in a class abstract to use it, you must override this method in the subclass. But, overriding is not possible with static methods.
First, a terminology lesson. Next, explaining why you can't do that. Third, an alternate solution that's not ideal but may get you where you need to go.
From the looks of your question, you're not trying to "override" a class, you're trying to rewrite the class. A class rewrite is where you add configuration nodes to Magento in order to tell it
Instantiate this class instead of that class
An "override" is where you copy a class from the Magento core into the local code pool. In other words, copy
app/code/core/Mage/Rule/Model/Abstract.php
to
app/code/local/Mage/Rule/Model/Abstract.php
An override is where you tell Magento "use this class file instead of the other class file". Similar, but different from a rewrite. Rewrites are considered better practice because they're less destructive, and less likely to cause problems with upgrades and extension compatibility.
You can't rewrite an abstract class. The rewrite system works because Magento uses a factory pattern to instantiate model, blocks, and helpers
$class = Mage::getModel('catalog/product');
What a rewrite does is, in pseudo code
function getModel($model)
{
if("can I find a rewrite configuration for $model")
{
//instantiate the model with the rewrite
}
else
{
//instantiate the normal model
}
}
Since an abstract class is never instantiated, it can never be rewritten.
From what I can tell, there's only three classes that inherit from this abstract class in a standard Magento installation.
catalogrule/rule
Mage_CatalogRule_Model_Rule
rule/rule
Rule/Model/Rule.php
salesrule/rule
SalesRule/Model/Rule.php
You could add a rewrite for each of these classes individually, ideally putting your new logic in a shared helper class. You'd need to handle extensions or custom code in a similar way, but it's one possible path forward.
The other alternative is to use a traditional class override and copy
app/code/core/Mage/Rule/Model/Abstract.php
to
app/code/local/Mage/Rule/Model/Abstract.php
This will let you modify a single Abstract
class, but you'll need to merge any changes from upgraded versions into this class — and you may cause system problems when (not if) you forget to do that.
Good luck!
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