I want to change the method collect() from


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.:




I also tried xml, but it didn't work (as expected) since you can't override an abstract.


Underlying my question, I feel I misunderstand this part of Magento. What is the difference between

  1. extending (without overriding) and how would you call the model in xml? Using :


  2. Using override in .xml (like above xml, rewrite)

  3. Using the autoload technique.


1 Answer 1


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 what Mage_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:

  1. Extending inherits the rewritten class and you only have to change the functionality of a particular method, (not the entire class).
  2. The xml above is rewriting a class. Putting items in the local code pool overrides them.
  3. Autoloading is a bit of a big topic, but simplistically:
    1. A class attempts to instantiate.
    2. The autoloader maps the class name to a file name, (example: Mage_Catalog_Model_Product maps to Mage/Catalog/Model/Product.php.
    3. Magento attempts to find this mapping in one of the three code pools (local, community, core) and in the lib directory.

A google search of autoloading in Magento will give more in depth process of autoloading.

  • I do understand the disadvantages of overriding an abstract class. I need to collect product and shipping fees to fix a new grand total when some products are from specific manufacturers. Basically, I'm adding a fix fee at the end of the invoice. I don't remember why an Observer didn't work but looking at where I am now it might be something to do. Still, I don't know how to hook on collect() and use the $address parameters with and observer. As for now I will try extending Mage_Sales_Model_Quote_Address_Total_Grand.
    – Pobe
    Feb 25, 2015 at 17:20
  • Maybe I should try extending the abstract class with the observer one. I'll try that to!
    – Pobe
    Feb 25, 2015 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.