In this tutorial, I will teach you how to upgrade Magento 1 extensions from AheadWorks when these ones were customized for your purposes and you don’t want to lose this customizations simply copying a new version of the extension over the previous one. To do this we will use patches.
Note: although this tutorial is directed to aheadWorks’ extensions you can skip a few steps or adapt them to any other extension.
Before we get started, we need the files from the previous version of the extension — the same version currently installed in our Magento store source tree, i.e, those ones we have customized with our code — and we need the files from the newer version of the extension. So we will create a diff file from these two versions.
For sake of simplicity, I will use the Follow Up Email extension to exemplify the steps necessary.
Also, I use Linux (Ubuntu 16.04) to do these upgrades. So if you use another OS (Operating System.).. well it’s time to you considering to change for a great OS. 😉
Preparing the files before creating the diff file
In a temporary folder, uncompress the previous version of the extensions:
mkdir -p ~/tmp/aw_followupemail-3.6.4 cd ~/tmp/aw_followupemail-3.6.4 unzip ~/Downloads/aw_followupemail-3.6.4.community_edition.zip
Remove unnecessary files and merge the folders step1 and step2 into current folder:
rm LICENSE.txt readme.html mv step1/* . cp -r step2/* . rm -rf step1 step2
Remove the module AW_All and related files. This module came with all extensions from AheadWorks and sometimes an older release can overwrite a newer release. AheadWorks recommends you use the newest release of this module:
rm -rf app/code/local/AW/All app/etc/modules/AW_All.xml app/design/adminhtml/default/default/layout/aw_all.xml app/design/adminhtml/default/default/template/aw_all/ js/aw_all/ skin/adminhtml/default/default/aw_all/
Repeat the steps above for the newer version of the extension:
mkdir -p ~/tmp/aw_followupemail-3.7.0 cd ~/tmp/aw_followupemail-3.7.0 unzip ~/Downloads/aw_followupemail-3.7.0.community_edition.zip rm LICENSE.txt readme.html mv step1/* . cp -r step2/* . rm -rf step1 step2 rm -rf app/code/local/AW/All app/etc/modules/AW_All.xml app/design/adminhtml/default/default/layout/aw_all.xml app/design/adminhtml/default/default/template/aw_all/ js/aw_all/ skin/adminhtml/default/default/aw_all/
Creating the diff file
Now we will create a diff file with the differences between the files from the two versions.
cd ~/tmp diff -uNr aw_followupemail-3.6.4 aw_followupemail-3.7.0 > aw_followupemail-3.6.4_3.7.0.diff
Applying the patch to the customized extension
Now that we created the diff file we can apply this file to the store source code, using the patch command:
cd /magento patch -N -p1 < ~/tmp/aw_followupemail-3.6.4_3.7.0.diff
Resolving the conflicts
I don’t like to arrive at this point but sometimes the patch command found conflicts that it can’t solve by itself. In this case, you must solve these conflicts.
If there any conflicts between your current code and the patch — certainly because you customized the extension –, the patch command should have output messages like Hunk #x FAILED at xxx. Also, the file which the patch failed was saved with the file extensions .rej and .orig
There are some methods to solve theses conflicts, but I prefer to use to do a 3-way merge using the meld tool.
For each file with conflicts, execute the meld with three parâmeters: the previous version file; the file in your Magento source tree; and, the newer version file. Ex:
meld ~/tmp/aw_followupemail-3.6.4/app/code/local/AW/Followupemail/Helper/Image.php app/code/local/AW/Followupemail/Helper/Image.php ~/tmp/aw_followupemail-3.7.0/app/code/local/AW/Followupemail/Helper/Image.php
Looking at the picture below you see three panels with the files opened (from the left to right): the previous version (before your customization); the file in your source tree (customized by you); and the new version (without any customization).
You must compare the previous version (left panel) with the new version (right panel) and apply the modifications to the file with the version customized by you (middle panel). After that, save the file (control+S) and close the meld.

After all, you can remove the files with .rej and .orig files extensions. The following commands find and remove theses files:
find ./ -name "*.orig" -exec rm {} \; find ./ -name "*.rej" -exec rm {} \;
That’s all folks! I hope it helped you. Please leave comments below.