I have and (community) extension that switches the product images when you change the options of a configurable product. This works great.
I've also developed some extension that changes the select elements of the configurable options to images and labels. Again this works as expected.
Now the issue. Both of them need to remove from the head block the varien/configurable.js javascript file that handles the configurable products and add their own file. So basically both of them override the js class Product.Config. Both of them need to override the initialize function in the class so I cannot add in my extension Product.Config.prototype.initialize = function(){...}. Or can I?
As you can imagine they don't work together.
Is there any way to solve these kind of conflicts without cloning the changes that the community extension brings to the table into my js file and building on that?

  • Not sure on the particulars but with Prototype you have inheritance - so you could make your customisations extend the community one and then instantiate your class (for example MyProduct.Config) instead of Product.Config. – Kristof at Fooman Sep 5 '13 at 19:03
  • This means I have to change the line in the configurable products template from spConfig = Product.Config(...) to spConfig = MyProduct.Config(...), right? if so, please post this as an answer, maybe add a little example :). My prototype skills could use some improvements. – Marius Sep 5 '13 at 19:22

As mentioned in my comment above, depending on the code involved you can subclass the prototype Product.Config and inherit from it. So for example something like this:

var MyProduct.Config = Class.create(Product.Config, {
    initialize: function($super, config){
        $super(config); //this calls the parent initialize
        //do your custom stuff here        

More info on prototype's inheritance is here.

As you have guessed afterwards you would use

spConfig = MyProduct.Config(...)

instead of

spConfig = Product.Config(...)
  • What do you know...it works. Indeed I had to change the spConfig value, but this doesn't bother me that much since I already have to work with a custom theme, and the configurable.phtml file already has some custom code. I've even wrapped it in an if statement if (typeof MyProduct == 'undefined'){spConfig = Product.Config(...)} else {spConfig = MyProduct.Config(...)} in case someone disables my extension in the future. Thanks. – Marius Sep 6 '13 at 7:41
  • No probs - glad to hear it works. – Kristof at Fooman Sep 6 '13 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.