Understanding and Detecting Magento Extension Clashes or Conflicts

April 16, 2013

This article will give an overview of Magento extension clashes (sometimes called conflicts) and then run through a few ways you can find them in your installation.

I get asked at least once a week a question like ‘What is a Magento Extension Clash‘ or ‘How Do I Find Extensions that Conflict‘. So, if you’re reading this, you probably just asked me, and I probably just sent you a link to here. That was a bit meta-blog, sorry about that. On with the article.

What is a Clash?

Magento extensions can override core functionality using what’s called a class rewrite. That’s when your extensions configuration file tells the core of Magento to use your custom PHP class, instead of the core one. Typically the custom class will sub-class the core one, and only override the methods that need to be changed. Here’s an example of that, firstly showing a snippet of rewrite xml for a core model:

<!-- ... snip config.xml ... -->
        <models>
            <core>
                <rewrite>
                    <email>Aschroder_Email_Model_Email</email>
                </rewrite>
            </core>
        </models>
<!-- ... snip config.xml ... -->

And then the corresponding class, notice it overrides the core version:

 
class Aschroder_Email_Model_Email extends Mage_Core_Model_Email {
 
// only add methods here that override the ones we want to change in Mage_Core_Model_Email
 
}

So that’d all be well and good if everyone only installed my email extension in their Magento store, but they don’t. They install PDF email attachments, email emoticons, email monkeys and god knows what else. So the rewrite that my extension needs to work, may very well not happen, because another extension rewrites the same class.

The same sorts of things can happen all over Magento, and typically the bigger and more complex and extension is, the more rewrites it will need, and the bigger the surface area for conflicts and clashes.

You might be thinking: “Gosh, it’d be great if Magento Connect ran some sort of rudimentry test for compatibility before installing extensions willy-nilly in Magento Stores” and if you are, that means you’re one of the Good Guys™.

There are other potential clashes too, like extensions listening for and manipulating the behaviour of the same events, but those tend to be less likely, and arguably less problematic when they occur.

Detecting Extension Conflicts

When a clash is occurring it will mean some part of an extension is not running when it is supposed to, so in an email SMTP extension that might manifest itself as the emails being sent through the default local sendmail instead of the configured SMTP server, simply because the code to send via SMTP never runs.

There’s a few options here for actually finding out if clashes exist, and what they are. There’s a paid-for extension, which is probably the path of least resistance if you’re non-technical.

There’s a new tool on the scene that’s been getting some excellent features added by Christian Münch in a prolific release cycle called n98-magerun which is a command line tool that can identify model rewrites for you, along with heaps of other useful Magento commands.

This lists all rewrites:

n98-magerun.phar dev:module:rewrite:list

This lists clashes:

n98-magerun.phar dev:module:rewrite:conflicts

Update: @therouv quite rightly noted I had forgotten Firegento which is an extension that can show you extension conflicts. It’s also got a bunch of other useful features, you should check it out.

Lastly, if you’re long in the tooth and sceptical of new things, you can always grep for your specific rewrite in the config.xml files. Something like this would find email rewrites for example:

find . -name "config.xml" | xargs grep "<email>"

So if you found more than one such rewrite, you’d know you had a problem. It’s a quick, easy non-invasive approach if you’re on the hunt for something specific.

One quick update here from the Twitter – this will find specific rewrite sections in the XML:

Thanks to Michael for the tip!

If I missed an obvious way, please let me know and I’ll update.

Fixing Clashes

Sadly there’s no silver bullet here, for any given pair of clashing extensions there may be a different required solution, sometimes there’s no solution and the only way to resolve it is to actually modify the behaviour of one or both extensions.

In the best case, the two extensions override different core methods, that have no affect on one-another – in which case you can simply add them into the class hierarchy and all would be OK (but you should test that!).

Worst case you need to consult with your extension provider and they may have an out-of-the-box solution if the clash happens often, or you may need to pay for some custom development.

Good luck! And always ask yourself, do I really need this extension? before going crazy in Magento Connect.

Ashley

Posts

Hi! I'm Ashley Schroder, a Software Engineer from New Zealand - this is a collection of notes on my experiences with Ecommerce Web Development, particularly Magento Development.

Are Your Customers Getting The Magento Emails You Send?

MageSend Magento Email sending with Amazon SES

I have made a premium Magento Extension called MageSend. MageSend makes it simple and easy to send using Amazon's highly reliable SES email service.

The extension is $99, and comes with a complete money back guarantee, please check it out, I am confident it will resolve any email sending problems with your Magento store.

3 responses to Understanding and Detecting Magento Extension Clashes or Conflicts

  1. Excellent post as always Ashley. =]

  2. Hi Ashley!
    I’m writing you because I’m trying to install ASchroder.com SMTP Pro Email – Free and Easy Magento Emailing for SMTP, Gmail or Google Apps email. in my website but when I get to de Magento Connect Manager and I paste extension key to install http://connect20.magentocommerce.com/community/ASchroder_SMTPPro the result is Connection Error try again later.
    My version of Magento is 1.7
    Do you have any idea of what may be the problem?
    Thanks

  3. Great write up Ash! For the super lazy, there’s also this guy:
    http://www.boostmyshop.com/english/magento-extension-conflict.html

    I’m not affiliated but do have personal experience, it equates to the n98 tool everytime and also suggests fixes (always removing one rewrite and extending one class from the other, thus chaining deps, but it works)