Magento Depends – Introduction and Example for in Magento

magento-1.6php-5.4

Am new to magento I have created custom module(front & back office). So here I want to know structure/flow of depends? And how it works depending on other modules?

Can you give me brief introduction/examples for this?

Thanks in advance.

Best Answer

The <depends> tag should be used if you create a module that impacts an other one.
For example if you create something that affects the products you should add in your declaration file (app/etc/modules/Namespace_Module.xml) this:

<depends>
    <Mage_Catalog />
</depends>

This insures that your module configuration will be loaded after the Mage_Catalog configuration.
Also if on a Magento instance the catalog module is disabled you will get an error message that your module cannot be used because it depends on the catalog module and you should disable that also.
You should also add this dependency if you use in your module one of the classes in a different module.
Why is this useful? Let's say that you want to override some tag from config.xml or system.xml. Magento loads configurations from xml files by merging them and overriding the leaf nodes. If you module is loaded after an other one you can override some leaf xml node by adding in the specific xml the same path.
Here is an example. Let's say that you want to be able to allow in system configuration to change the list mode (grid/list) only at website level. You need to add in your system.xml this:

<config>
    <sections>
        <catalog>
            <groups>
                <frontend>
                    <fields>
                         <list_mode>
                            <show_in_store>0</show_in_store><!-- this disables it on store view level -->
                         </list_mode>
                    </fields>
                </frontend>
            </groups>
        </catalog>
    </sections>
</config>
Related Topic