Extending a Third Party Module in Magento

Adding Magento modules give us the ability to extend the default functionality. Sometimes when developers are attempting extending a third party module in Magento, their changes are overwritten when the module is upgraded.

This is usually because changes are made within the third party modules themselves and not within a module that extends them.

Even if the modules that do the extending are created, sometimes the order in which Magento loads its modules causes customisations made by the developer not to show, such as overriding layout configuration.

Magento by default will loads its modules alphabetically. As an example, let’s assume you wanted to extend the Magestore_RewardPoints module. If your extending module was called Custom_RewardPoints, the Magestore module’s configuration would be loaded after the custom extension’s config.

This of course does not mean that you have to rename your module so that it loads after any ‘M’ modules. A easy way of ensuring your module loads after a third party module is adding the <depends> node within the module declaration file.

// app/etc/modules/Custom/RewardPoints.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Custom_RewardPoints>
            <codePool>local</codePool>
            <active>true</active>
            <depends>
                <Magestore_RewardPoints />
            </depends>
        </Custom_RewardPoints>
    </modules>
</config>

Magento will then adjust the sorting of the load modules as per the <depends> nodes within each module.

Now configuration within the Magestore module can be overridden.

For example, the Magestore layout file adds the following CSS file.

// app/design/frontend/base/default/layout/rewardpoints.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="head">
            ....
	    <action method="addCss">
                <stylesheet>css/magestore/transactionpoint.css</stylesheet>
            </action>
            ....		
        </reference>
        ....
    </default>
</layout>

This could be removed from within the Custom_RewardPoint’s layout file.

// app/design/frontend/base/default/layout/custom/rewardpoints.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="head">
	    <action method="removeItem">
                <type>skin_css</type>
                <name>css/magestore/transactionpoint.css</name>
            </action>		
        </reference>
        ....
    </default>
</layout>

To add layout configuration, ensure that the layout file has been defined within the module’s config.xml configuration file.

// app/code/local/Custom/RewardPoints/etc/config.xml

<?xml version="1.0"?>
<config>
    <frontend>
        <layout>
	    <updates>
                <custom_rewardpoints>
                    <file>custom/rewardpoints.xml</file>
                </custom_rewardpoints>
            </updates>		
        </layout>
    </frontend>
</config>

Module dependencies are important to help keep Magento modular, and avoid any issues with module upgrades.