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?
1 Answer
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 theconfigurable.phtml
file already has some custom code. I've even wrapped it in an if statementif (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 -
spConfig = Product.Config(...)
tospConfig = MyProduct.Config(...)
, right? if so, please post this as an answer, maybe add a little example :). My prototype skills could use some improvements.