Magento Dev Best Practices: Modifying 3rd Party Extensions

Often times there are occasions where you need to modify the functionality in a 3rd party module. If you find yourself in that situation, the best practice here is to not modify it directly. Write a module that extends the 3rd party extension! In doing this, you save headaches if you ever need to upgrade the extension, or if you find that you need to revert your changes and go back to the original, it’s easy.

Perhaps the most important aspect of properly extending a module is by setting the dependency:

Dependency

In your modules xml file in app/etc/modules, you can add a block of code to make your module depend on the 3rd party extension you are trying to extend. By doing this, you cause your new module to be loaded after the extension you are adding the dependency for. This is good because your config.xml information will be loaded afterwards, and therefore your rewrites, event observers, etc. will take priority, so there’s no need to comment out any code in the 3rd party extension’s config.xml file. Here is an example of your xml file if you were extending an extension named Awesome_Extension:

<config>
    <modules>
        <My_ModuleExtender>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Awesome_Extension />
            </depends>
        </My_ModuleExtender>
    </modules>
</config>

If You Must…

If there is some reason that you need to actually modify the 3rd party extension files, at least comment and document it like crazy. Keep a txt file or something in the extension’s root folder and list out every file in the module that you modified, the purpose of the modifications, the new/changed functionality introduced, etc. Also, keep all of the original code. Comment out what you are changing, add your modified code, and make sure that the code is clear as to what is new, and what is original. Keep in mind that you (or someone else) may need to undo your changes, or upgrade the extension at some point, so make it as easy as possible for someone to do that in the future.

This entry was posted in Best Practices, Magento. Bookmark the permalink.

2 Responses to Magento Dev Best Practices: Modifying 3rd Party Extensions

  1. Josh, Thank you so much for this GREAT series of best practices and insight for Magento, I had to blog about them in my Spanish Magento blog:
    http://magentoextensiones.com/mejores-practicas/desarrollo/
    FYI, gracias! :)

  2. Pingback: Magento Dev Best Practices: Modifying 3rd Party Extensions | Prattski | Magento & Web Development | Kyle Cannon's Blog

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>