Tips for overwriting the magento core files

Tips for overwriting the magento core files

In this tutorial i will go through the process of overwriting the magneto core and community files to your local folder.
As we all know it is the first thing that we all learn while working in magento is “Don’t Ever Modify The Core Files“. This statement is very true because it creates problem if we need to upgrade to another version and also to find out the modified files. That’s why we override the core modules to our local files.Some times we need to override the modules from Community folder too.

We can override the modules block or models or controller by rewriting it config.xml file in our local module and then apply our changes there. But overriding the files using rewrite is not always easy.There may occur some problems and you may not be able to override those files.So what could we possibly do in these cases?
I also have faced this problems sometimes, when you think all your configuration is correct but the files in not overridden.
The solution i am going to tell is not the best way of doing it but it works and doesn’t create other issues.

The solution is to make the same directory structure in your “local” folder as the files that you want to override and paste that file there. For example if you want to override “app/code/core/mage/adminhtml/block/customer/grid.php“, you just need to create “app/code/local/mage/adminhtml/block/customer/grid.php“.

And in this file you can make the changes.No need to do any other changes.

Now after that i have told the solution i want to tell what is going on. Actually we aren’t overriding the file we are overwriting it.To understand this first you need to understand how magento reads the file.I will not explain the whole flow but for now it is that at first it searches file at “local” folder than “community” and at last in “core” folder.So if you create the same folder structure magento first look to your local folder and it finds it and execute it.
The problem with overwriting is you need to copy the whole file because inside it there may be many functions and if you delete any one function from there than magento will not look for that function in core and will display error. But overriding is a different case if you override the file than you can only add or modify those functions in your overridden file and no need to copy other unrelated functions in your file.

Now from above tutorial you will be able to overwrite the magento files and another thing is you may have understand the difference between overriding and overwriting.