As you may have noticed, all the models are referred as Mage::getModel(’module/specific_class’). There are variations such as getSingleton and getResourceModel, but the idea stays the same.
Say you want to extend ‘catalog/product’ model. By default it refers to Mage_Catalog_Model_Product class. Which is declared in Mage/Catalog/etc/config.xml
Our goal is to add a new method getDefaultCategory(). Steps are:
* Create new module Mage_MyCatalog
* class Mage_MyCatalog_Model_Product extends Mage_Catalog_Model_Product
* public function getDefaultCategory()
* create Mage/MyCatalog/etc/config.xml that contains:
Now, all Mage::getModel(’catalog/product’) will create instances of Mage_MyCatalog_Model_Product with my custom method and all the original ones! Still, Mage_Catalog is upgradable.
It is possible to override the whole model group, and same goes for blocks, helpers and controllers.
With themes it’s similar but a bit different. We leave intact the original themes and create new ones for our customizations. When we use them, Magento will take the files that exist in there or fallback to the files in the original themes.