One of the greatest things about the Magento eCommerce platform is its flexibility. From online stores selling simple office supplies to complex customizable tennis shoes, the default Magento installation can create it by expanding on the core software and tools available. However, all things come at a price. The more customization you add to the store, whether it’s an extension or custom code, the more care necessary to ensure your default install remains upgradeable. Magento upgrades often include a number of bug fixes, some may affect you and others may not. Some of the more noticeable improvements would be when a core module is updated/improved or when core code is optimized to increase overall site speed. Whatever the reason is, upgrades are a good thing. Here are a few tips that can help you ensure that your Magento upgrades run as smoothly as possible:

Magento Fall-back Hierarchy

One of the cool features of Magento themes is the fall-back hierarchy. To put it in simple terms, you have a base package with a default theme, and within that theme is every template that the store can have. When a new theme is created (lets call this theme "Groove"), the templates in Groove override the ones in the default theme. When one of the templates isn’t in the Groove theme, it will “fall back” to the default theme for the file. What is so great about this feature is that you can create a new theme to do a very simple task and only override one or two files, or you could override every template and completely customize your store... Cool, right? One thing developers tend to forget is, when you upgrade your install, Magento automatically adds any template updates to the base package's default theme, overwriting the files that were there. If you haven’t setup your themes properly, you can start running into problems. Pages can start displaying incorrectly, code won't function properly, etc.

One way to avoid this problem is to make sure you aren't editing your store in the base package's default theme. An even better way would be to not use the base package at all, and create your own package with the single "Groove" theme inside of it, taking advantage of the fall-back hierarchy to ensure you are still getting the benefits from the upgrades.

Preparing Your XML for Updates With local.xml

Fortunately, layout XML files follow the same fall-back hierarchy as your template files. You can create an entire folder of XML files in the Groove theme and they will override all of the XML files in the base package's default theme. However, a better way to take advantage of some of the default features in the Magento platform is to use the local.xml file. In a fresh install of Magento this file doesn't exist, so you must create it. To give you an idea of what this file does, Magento will load all of your XML files for setup, configuration and layout. One of the last things it does before rendering the page is look for a "local.xml" file in your layout folder. This XML file can be used to essentially override every single layout XML file that was loaded before it. If you have set up your themes correctly, it will check for the local.xml file in the Groove theme before it looks for it anywhere else. This means that your theme can have a single XML file that can override all of the other layout files and eliminate the need to have multiple XML files in your custom theme.

There are plenty of other great reasons to use the local.xml file but when you use it in this way you get to take advantage of updates to the base package's layout XML as well. Which we all know is awesome.

Alright, so that's enough front end talk, what about the back end of Magento?

Core Code... Who Needs It?

You may have heard how you shouldn't edit core code within Magento. It is true that editing core code can lead to problems when it comes time to upgrade, but there is a little trick to changing the core without breaking your installation. I do, however, recommend consulting with your Magento Partner before committing any changes.

One of the big problems with editing Magento's core is that most bug fixes are typically in the core. Meaning all that hard work you put into making your header load external javascripts or having your checkout automatically add a scratch-n-sniff sticker to every order is gone! Fortunately for us, and sticker collectors everywhere, there is another place where we can make our changes that won’t break the core or the upgrade process. If you go to your Magento install on the file system and navigate to the app/code directory, you will see "core" and right below that is another folder named "local." That's where the magic happens!

Just like the front end, the back end will load all of the core methods and at the last second check the local directory for any updates. If we were to put any updates in that folder, they could override any of the methods loaded before it. Say, for instance, we wanted to edit the file app/code/core/Mage/Foo/Bar.php. What we could do is mimic the exact same directory structure in the local directory (app/code/local/Mage/Foo/Bar.php) and override/extend the methods in Bar.php. Then when you upgrade, if Bar.php gets updated in the core, the code in the local directory will then be overriding/extending the new, updated method, and saving you the work of going back in and manually updating the core every single time.

Upgrade Your Extensions

The hardest thing about upgrading your extensions is that sometimes an extension developer will fail to keep their extension up to date. It is important, when you are considering installing an extension, to note the update history of the extension. This can give you some insight into how well the developer keeps the extension updated. Choosing reputable extensions or buying a paid extension with support is a great way to ensure that your extensions will be working post-upgrade.

Do a Backup and a Dry Run!

The last thing before updating your install is to do a backup of your files and your database and try a dry run in your testing environment. You never want to test an upgrade in the production environment. Even if you have taken all the steps in this post, it is still better to be safe than sorry. Doing a dry run will not only help make the real upgrade smoother, but it may also show you some problem areas with the upgrade that you can resolve before upgrading your production environment.

In conclusion, the Magento fall-back hierarchy is a very powerful tool that should be taken advantage of, not just for upgrades. Using a local.xml file to override base XML layouts is a great way to take advantage of XML updates. Making sure that all of your core edits are inside of the local directory will keep your install running properly after an upgrade. Choosing the right extensions and keeping them updated will keep you from having problems with your upgrade. Finally, doing a thorough backup and a dry run will help you spot problem areas before the real thing.

Talk to Us

Tell us about your goals and we'll discover together how Groove can help you meet them.