Yireo - Extensions, tutorials and blog for Magento and Joomla!

Blog Tags

MageBridge Standard

Rewriting the Magento XML too many times

Thursday, 12 August 2010

Overriding the default behaviour in Magento is cool. But if it is done too many times, you might get into trouble. We were playing with some default grid-settings in the Magento backend, and found suddenly a conflict between three Magento modules trying to apply the same trick.

How to rewrite the Magento XML

Magento is all based on XML-code. Through XML-code various logical structures are defined - like the configuration, or the layout of the actual page. The XML-code is first read (streamed), then parsed, then interpreted. Now the cool thing is that during the parsing process, a third party module could redefine something that was earlier defined by the Magento core.

This is very cool and makes Magento very flexible: You can override just about anything in the entire Magento system.

Rewriting the orders-grid in the backend

Now the following XML-code could be placed somewhere in a XML-file to rewrite the orders-grid. This code should not be used as an example to do it yourself, but it's just printed here to give you a quick impression.

<config>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <sales_order_grid>My_Personal_Grid</sales_order_grid>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

The same trick applied too many times

The reason for this blog is not about explaining how to use XML-code in Magento. This blog is ment as a warning: The trick used above is very popular among Magento programmers, and when inspecting a customers Magento shop we found three third party modules applying the same trick:

  • Enzinger/GridActions
  • Kreditor/Kreditor
  • Sebastian/Export

The problem here is that only one of the three modules actually applies its trick, while the rest don't. This does not indicate a flaw in the design of these modules - it indicates a flaw in the design of Magento.

How to prevent it

Magento pogrammers should try to use Magento events wherever they can, but while the Magento system is already bloated with events, there might just be not enough. So sometimes a XML-override is the only way to go.

There is a much simpler way to solve this: Don't use too many third party modules. But that's probably a different discussion.

About Yireo

Yireo tries to help webdevelopers build successful Joomla! and Magento sites.

More about Yireo