Changing and Customizing Magento Code
This is an old revision of the document!
If you’re finding that you need to make changes to Magento’s code to fit it into your organization, you’re probably wondering what is the best way to make these changes so that you can keep your code separate from the main code.
The best way to keep track of all your changes is with a tool like Subversion (SVN) or CVS. You can use branches for the base Magento code. This will keep you customized files from being blatantly overwritten whenever you update Magento.
Here is an example code layout
my_project/ trunk/ scripts/ src/ (magento's code) data/ branches/ vendor/ magento/ app/ lib/ index.php
Under the “magento” directory, we have an export of Magento’s latest SVN (0.6 beta). Now, we can use SVN’s merge to copy the changes that happen to that one directory (branches/vendor/magento) into our main directory (trunk/src/). The first time, the changes will only be between revisions 1 and 2 (if don’t make any mistakes setting up the repository). But, every magento release, you will only have 1 revision change, for example: after making 100 changes to your store you are at revision 101. You update the Magento vendor branch with version 0.8 beta. Now you are at revision 102. And the difference between 101 and 102 contain all the Magento changes between 0.6.14400 and 0.8.2620 (imaginary magento numbers). So, when you merge 101:102 into your main/src directory, Subversion will do its best to only apply the changes, and not simply overwrite all your hard work with new files from 0.8.2620.
Most likely you will want to make a module that represent’s your company to hold all your specific changes. Start off by making a new directory like so:
code/ core/ community/ local/ XyzCorp/
Now, if you need to make changes to the Magento file, Mage/Catalog/Block/Breadcrumbs.php, you can add a new directory for the “Catalog” module under your XyzCorp directory, then a blocks directory and copy the file into this new directory.
code/ core/ community/ local/ XyzCorp/ Catalog/ Block/ Breadcrumbs.php
Change the class name inside the file by starting off with “XyzCorp” instead of “Mage”.
Strip out all the code you don’t need, and make it subclass the original class name (”Mage_Catalog_Block_Breadcrumbs”).