I want to change the method collect()
from
Mage_Sales_Model_Quote_Address_Total_Abstract
By what I've read it seems I can't rewrite it since it's abstract and it is never instantiate.
Looking around, the usual dirty trick is to use Magento autoload and copy the file and the exact path under /local/.
E.g.:
core/Mage/Sales/[...]/Abstract.php
to
local/Mage/Sales/[...]/Abstract.php
I also tried xml, but it didn't work (as expected) since you can't override an abstract.
<models>
<sales>
<quote_address_total>
<rewrite>
<abstract>Lebernard_Dropship_Model_Sales_Quote_Address_Total_Abstract</abstract>
</rewrite>
</quote_address_total>
</sales>
</models>
Underlying my question, I feel I misunderstand this part of Magento. What is the difference between
-
extending (without overriding) and how would you call the model in xml? Using :
parent::collect($address);
-
Using override in .xml (like above xml, rewrite)
-
Using the autoload technique.
Thanks
Best Answer
Technically, you are correct, you can override the class in the local code pool, but you should not. When you override a class, you own it, meaning you must now maintain it. This includes upgrades, etc. It is very bad practice.
Second, since an abstract class is never instantiated through the abstract factory pattern, (
Mage::getModel()
,Mage::getSingleton()
, etc) it will not work to rewrite it through configuration.Third, when you rewrite such a low level class, you should seriously reconsider your approach. What are you trying to accomplish? Are you trying to rewrite the
collect()
method for over 24 classes? I ask because this is whatMage_Sales_Model_Quote_Address_Total_Abstract
is inherited by. Perhaps you should rewrite a method call from a more specific class. Maybe check into an observer that will solve your issue.To answer your questions listed above:
local
code pool overrides them.Mage_Catalog_Model_Product
maps toMage/Catalog/Model/Product.php
.local
,community
,core
) and in thelib
directory.A google search of autoloading in Magento will give more in depth process of autoloading.