3

When working with the rwd theme and the configurable product image swatches on some products the product images are not changing when changing options.

Sadly this does not happen on all products or even with all product options.

There are no JavaScript errors and this is with the default template and clean Magento install.

1 Answer 1

3

The reason behind this is the function ConfigurableMediaImages.arrayIntersect. The problem here is that the function must take in two already sorted arrays. Unfortunately the theme does not guarantee this.

Making sure the two arrays are sorted before calling the method will fix this issue for my needs I ended up adding a new js file with the following code:

ConfigurableMediaImages.arrayIntersect = function (a, b) {
    a.sort();
    b.sort();

    var ai = 0, bi = 0;
    var result = new Array();

    while (ai < a.length && bi < b.length) {
        if (a[ai] < b[bi]) {
            ai++;
        }
        else if (a[ai] > b[bi]) {
            bi++;
        }
        else /* they're equal */
        {
            result.push(a[ai]);
            ai++;
            bi++;
        }
    }

    return result;
};

There is also a gist that covers this problem. Plus you can see the function has been copied from stackoverflow but the not about being sorted has been removed.

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.