
Override Magento Core Model Classes – Magento Customization

You must have noticed that sometimes you can’t use default Magento Models and require changes due to certain business logic you are about to follow. These changes are done to implement new functionality which are not part of existing Magento Installation. Overriding Controller is not difficult as you can copy the code from core in controller and keep the file in local directory. Now you can edit the class as per your requirement which will pretty much do the trick. You might know better and efficient way of doing this but that’s not a point here. I wanted to elaborate on how to override default Magento’s model class without even changing the core files. Tricky isn’t it?
In this article I am going to write a short code which will help you in overriding default Magento model without changing its core files. We have to create an extension which will do the trick. Simple difference between this extension and original class will be class name var_dump.
Now, we will choose any model class from core of Magento, in our case we will choose Mage_Wishlist_Model_Item which you can locate under app/code/core/Wishlist/Model/Item.php
In order to add new functionality in this class we will create a new module. What we are going to do now is to take a random model class from Magento core.
Let it be Mage_Wishlist_Model_Item located in app/code/core/Mage/Wishlist/Model/Item.php
What we want to do is to add new functionality to that class, so let’s make new module called as MagentoMagik_Wishlist (you can change the name as per your requirement)
Create app/code/local/MagentoMagik/Wishlist/model/ directory and copy app/code/core/Mage/Wishlist/Model/Item.php in that particular location.
Let’s rename class Mage_Wishlist_Model_Item to MagentoMagik_Wishlist_Model_Item.
Now, we have to add the line given below:
in loadByProductWishlist method
Now, let’s create MagentoMagik_Wishlist.xml in app/etc/modules/
and write the following code it in:
1 2 3 4 5 6 7 8 9 | < ?xml version="1.0"?> <config> <modules> <magentomagik_wishlist> <active>true</active> <codepool>local</codepool> </magentomagik_wishlist> </modules> </config> |
Now, create app/code/local/MagentoMagik/Wishlist/etc/Config.xml file and write the following code in it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | < ?xml version="1.0"?> <config> <modules> <magentomagik_wishlist> <version>0.1</version> </magentomagik_wishlist> </modules> <global> <models> <wishlist> <rewrite> <item>MagentoMagik_Wishlist_Model_Item</item> </rewrite> </wishlist> </models> </global> </config> |
This is merely an example of overriding the default Magento’s Model files and you can change the other model in similar way. All you have to do is plan what change you require and don’t hurt any Model which is required by Magento. I hope this example must have helped you in changing the default behavior. Please leave me a comment and share your experiences, problems with us.
-
New
-
priya
-
priya
-
http://www.magentomagik.com/ MagentoMagik
-
http://blog.magikcommerce.com/how-to-customize-the-magento-core-without-actually-changing-it/ How To Customize The Magento Core Without Actually Changing It | Magik
-
http://www.ave-nir.com Magento development
-
Pierrefay
- How To Setup & Manage Multiple Stores In Magento Commerce
- How To Install Magento Extensions - Magento Extension Installation Guide
- Extra Fee Magento Extension - Addtional Charges Extension
- Magik Slider Extension - Magento Community Extension
- How To Install A Magento Theme - Ultimate Magento Theme Tutorial
- Adding New Shipping Module In Magento
- How To Add Lightbox To Magento Theme
- Free Magento Theme - ElectroMagik
- How To Display Best Selling Products On Magento Store Home Page
- MagentoMagik Autocomplete Search Extension - Magento Extension
Magento Development
Magento Extensions
Magento Hosting
Magento How To
Magento Installation
Magento News
Magento Product Import
Magento Themes


