Override Magento Core Files – Simplest Way
There are several methods used for overriding magento core files. Here I’m going to explain one of simplest method to override core files in magento.
In this method to override magento core files, you don’t need to create your own module and write some xml in config.xml. Instead you can simply copy core file (which you want to override) and paste it in ‘app/code/local/Mage’ maintaining the same path of that php file. Then you can start editing this file, magento will read your file instead of the core file.
Below is an example :
=> If you would like to override ‘app/code/core/Mage/Catalog/Block/Product.php’ you need simply need it to put Product.php in ‘app/code/local/Mage/Catalog/Block/Product.php’. Doing only this will let magento read this file from local folder instead of core folder.
Reason for such behavior of reading from local folder to core folder is :
This process is called overriding Magento core functionality and is based on the fact that Magento sets its PHP include paths to first look in app/code/local/ then app/code/community/ and finally in app/code/core/. This has the effect that any files of the same name placed under the local or community name space will take precedence in loading, hence, we can override almost any core file in this way.
Demerits of Using Above Approach :
1. For one thing, we must override the complete core file and copy all the class functions. Once the overridden file is in place, this will be the file will be used instead of magento core file always. Given that most core classes contain several and many times a large number of methods it means that we are effectively overriding all those methods in our file.
2. This approach is not magento upgrade friendly, because of the above reasons.
3. This approach doesn’t work for controllers.