Blog
 

Review of Mxperts jQuery extension & conflicting overrides

Mxperts jQuery extension and conflicting overrides

Magento Experts (Mxperts) is the number one Magento related Blog in Germany. Today they released a Magento extension that allows you to easily load jQuery into your Magento store. You just have to install the extension and jQuery gets automatically loaded. In the configuration menu of your Magento backend there is a new section, where you can enable different settings like loading jQuery in the minified/compressed way or turning on/off the conflict mode. The extension keeps your jQuery version up-to-date but also allows you to specify a certain jQuery version to be loaded.

I was actually interested in how the extension places the jQuery script-tag into the html header. So I had a look into the source code. What they basically do is overriding the block Mage_Page_Block_Html_Head with their own Mxperts_Jquery_Block_Page_Html_Head. Within their custom block they override the getCssJsHtml() method and append their script-tags inside of it. At the the end they call the getCssJsHtml() method of the parent class Mage_Page_Block_Html_Head, merge their script tags with the rest of the head content and finally return it. The extension does perfectly what it was made for. Mxperts did a great job indeed!

I know it’s very common to override core classes within Magento extensions. I just asked myself what happens if two or more extensions override the same core class. To test what happens, I created a little extenstion with a block class which overrides the Mage_Page_Block_Html_Head class (just like the jQuery extension does). As I already supposed, only one override has effect in this case.

This means, the more extensions (which modify a core class) you install in your Magento Admin Panel, the bigger is the risk that two extensions override the same core class. In order to solve such a conflict I guess you either have to merge both conflicting classes into one single class or you chain the classes (ExtensionClassA extends Core Class and ExtensionClassB extends ExtensionA). Somehow this is a big lack in Magento extension development in my opinion. Please correct me if I’m missing something.

 
 
 

4 Responses to “Review of Mxperts jQuery extension & conflicting overrides”

  1. Sebastian E. says:

    You are quite right, this is a big lack in magento.
    The same in Typo3 mit Xclasses.
    I hoped the learned there a bit more. But they didn’t :-(

  2. http://joshribakoff.com/?p=81

    I was having the same problem of Magento extensions conflicting with each other, and found this post. I found the solution to merge code unacceptable and so I wrote a extension that fixes it. Full technical details on my hacks are on my blog, along with the extension’s download URL.

  3. [...] a little googling for “conflicting magento extension” I found a few links http://blog.velite.de/mxperts-jquery-extension-and-conflicting-overrides/ I know it’s very common to override core classes within Magento extensions. I just asked myself [...]

  4. i am very confused nice explanation thanks for sharing about Mxperts jQuery extension it more helpful to me continue posting

 

Leave a Comment