Core Module Override:
1. Magento sets its PHP include paths to first look in app/code/local/ then app/code/community/ and finally in app/code/core/.
2. 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
When to override core files:
- We want to change a piece of functionality in a core method so we copy the php file containing the code and modify one or more methods.
- We want to add a new method to a core block class, so it’s available for use in the phtml template so we copy the relevant core Block php file and add our method to it.
- We may have several modifications consisting of core functionality changes and additions over several files.
When we should override core to app/code/local/Mage path:
Answer is NEVER. But ??
- For one thing, we must override the complete core file because we can’t trim out the stuff that we don’t want changed since we would lose all that functionality and most likely break Magento.
- Once the overridden file is in place, this will be the file and code Magento will be using from now onwards.
- 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.
What kind of issue will face :
- our customizations are going to be preserved after a Magento version upgrade?
- Yes but, in this scenario we don’t want config.xml files.
- what if the new Magento version has changes in the very files we have previously overridden? What if they have newly implemented methods or bug fixes in existing methods? Since our override will always take precedence, these new features and fixes will never be operational as our override runs all the old code. If you’re lucky, you may get an error report else our magento functionallity will lose
- You can see the problem now, right? After each upgrade, you will have to go and check all your app/code/local/Mage/ overrides and compare them to the new core files and port any core changes to your local override in order to maintain your site’s integrity.
- If you have lots of such overrides, this will be tedious.
Then Why i want to override to local/Mage :
- Its try to avoid but temporary choice to override from core.
- If you want to quickly try a core modification to see if it will solve your task as a proof of concept and When you are satisfied, you remove your override and implement a proper Magento extension with rewrites.
- If you are implementing a temporary override of some core functionality that you will remove after your task is complete.
- In some scenarios, local Mage overrides are the only way to achieve customizations. (Ex: Abstract class / Controller , abstract class – class is simple extended by magento and its object is not created, overriding won’t work.)