Search code examples
magentomagento-1.9

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?


Solution

  • 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>