1

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?

2
  • 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. Commented Sep 5, 2013 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
    Commented Sep 5, 2013 at 19:22

1 Answer 1

4

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(...)
2
  • 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
    Commented Sep 6, 2013 at 7:41
  • No probs - glad to hear it works. Commented Sep 6, 2013 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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