Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Product.ConfigurableSwatches is not a constructor in Magento 1.9.3

I'm using Magento 1.9.3.1 and facing below error on configurable product detail page

TypeError: Product.ConfigurableSwatches is not a constructor

Why am I getting this error and how can I fix it?

like image 899
Yogesh Avatar asked Dec 03 '22 23:12

Yogesh


1 Answers

That seems to be a bug in Magento since I was able to reproduce it on a fresh installation when the following two conditions are meet:

  • Configurable product with a config attribute other than color.
  • Configurable swatches are disabled for that attribute.

You can solve it by checking if Product.ConfigurableSwatches exists before calling it:

1) Open this file: app/design/frontend/rwd/default/template/configurableswatches/catalog/product/view/type/configurable/swatch-js.phtml

2) Change this:

<script type="text/javascript">
    document.observe('dom:loaded', function() {
        var swatchesConfig = new Product.ConfigurableSwatches(spConfig);
    });
</script>

To this:

<script type="text/javascript">
    document.observe('dom:loaded', function() {
        if (Product.ConfigurableSwatches) {
            var swatchesConfig = new Product.ConfigurableSwatches(spConfig);
        }
    });
</script>
like image 182
Daniel Kratohvil Avatar answered Jan 09 '23 21:01

Daniel Kratohvil