Magento2: JS Error in swatch-renderer.js on product detail, with configurable product having multiple swatch attributes, after selecting a swatch

Created on 18 Jan 2017  路  13Comments  路  Source: magento/magento2

Preconditions

  1. Magento 2.1.3.
  2. PHP 7.0.10 & PHP 5.6.10 (assumed any version, since it's a JS error).
  3. Observed in Chrome 55.0.2883.95, but assumed any browser, since its a straightforward error.

Steps to reproduce

  1. Enable the Blank theme.
  2. Add a configurable product that has multiple swatch attributes, with simple products that represent the possible configurations. I made the attributes required, not sure if that matters.
  3. Open the browser's console.
  4. On the product's detail page, select any of the swatch attributes.
  5. Check the console for the JS error.

Expected result

  1. No JS error.

Actual result

JS error: "Uncaught TypeError: Cannot read property 'oldPrice' of undefined"

js_error

Additional Comments

This error happens because result will will end up being undefined if not all the possible swatch attributes have been filled in. I believe this is because $widget.options.jsonConfig.index only contains full "paths", where all swatch options have been selected, not partial paths.

A simple check of results's value will likely resolve the issue. I'm very new to Magento, so I'm not confident enough to assume this is the best approach.

Thanks!

Catalog Fixed in 2.2.x Format is valid Ready for Work needs update bug report

All 13 comments

Confirmed that it's happening on Magento 2.1.3

Hi guys,
Anyone found any solution yet?

Same error.
capture

Also in 2.1.5 with sampledata!

@pat75007 The only solution I've found is to override swatch-renderer.js, and wrap the issue if statement in another if statement. This worked for my situation, but I don't know if it impacts any setups others may be using.

if (result && typeof result.oldPrice !== 'undefined') {
    if (result.oldPrice.amount !== result.finalPrice.amount) {
        $(this.options.slyOldPriceSelector).show();
    } else {
        $(this.options.slyOldPriceSelector).hide();
    }
}

Hello. We reproduced this bug on version 2.1.3. But in develop version, that is 2.1.7 for Your case this very bug seems to be fixed as we have not been able to reproduce it on. So please let us now if You still can reproduce this issue on 2.1.7. Thank You.

@AlexWorking I believe we are experiencing this issue after updating from 2.1.2 to 2.1.7

swatch-renderer.js:714 Uncaught TypeError: Cannot read property 'oldPrice' of undefined at $.(anonymous function).(anonymous function)._UpdatePrice (https://www.screenshotsinc.com/pub/static/frontend/Magento/luma/en_US/Magento_Swatches/js/swatch-renderer.js:714:23) at $.(anonymous function).(anonymous function)._UpdatePrice (https://www.screenshotsinc.com/pub/static/frontend/Magento/luma/en_US/jquery/jquery-ui.js:402:25) at $.(anonymous function).(anonymous function)._OnClick (https://www.screenshotsinc.com/pub/static/frontend/Magento/luma/en_US/Magento_Swatches/js/swatch-renderer.js:548:25) at $.(anonymous function).(anonymous function)._OnClick (https://www.screenshotsinc.com/pub/static/frontend/Magento/luma/en_US/jquery/jquery-ui.js:402:25) at HTMLDivElement.<anonymous> (https://www.screenshotsinc.com/pub/static/frontend/Magento/luma/en_US/Magento_Swatches/js/swatch-renderer.js:495:32) at HTMLDivElement.dispatch (https://www.screenshotsinc.com/pub/static/frontend/Magento/luma/en_US/jquery.js:5226:27) at HTMLDivElement.elemData.handle (https://www.screenshotsinc.com/pub/static/frontend/Magento/luma/en_US/jquery.js:4878:29)

Issue can be seen live @ https://www.screenshotsinc.com/gildan-adult-dryblend-50-50-t-shirt if that is any help.

Edit: Issue is no longer viewable at the live URL, as the work around @kfriend provided above seemed to do the trick.

This is also happening for us on Magento v2.1.7
Cannot read property 'oldPrice' of undefined in swatch-renderer.js:714

Still happening on 2.1.7. But seems to be fixed on 2.2, haven't tried it though..

Any update on this?

Hello @kfriend. Based on Your issue an internal issue were created - MAGETWO-70849. You'll be informed immediately after the issue is fixed. Thanks for reporting.

Duplicate of #7959

Patched in develop branch and 2.2 as MAGETWO-69541

Issue has been fixed in 2.2 and will be released very soon

Was this page helpful?
0 / 5 - 0 ratings