Magento: Override Models

You can override model in Magento in following way.
Steps to override Model in Magento:
1) When we override the model in the module, we should not change the core model files directly. To do this, we add following xml in config.xml inside our custom module:


2) We create a new custom class in our model folder in our custom module.
For Model to be overrided: app/code/local/Mynamespace/Catalog/Model/Product.php
class Mynamespace_Catalog_Model_Product extends Mage_Catalog_Model_Product


For Resource Model to be overrided: app/code/local/Mynamespace/Catalog/Model/Resource/Product.php
class Mynamespace_Catalog_Model_Resource_Product extends Mage_Catalog_Model_Resource_Product

For Collection Model to be overrided: app/code/local/Mynamespace/Catalog/Model/Resource/Product/Collection.php
class Mynamespace_Catalog_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection

Thats’s it! You have overrided the core models.
Note: We can only override the classes for which objects can be created. We can not override the abstract classes for which no object is created.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s