Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS error on product page Cannot read property 'oldPrice' of undefined #7959

Closed
katesuykovskaya opened this issue Dec 26, 2016 · 19 comments
Closed
Assignees
Labels
bug report Component: Catalog Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@katesuykovskaya
Copy link

Preconditions

  1. M 2.1.3

Steps to reproduce

  1. Create conf. product on 2 swatch attributes (for ex. color and size) with assigned simple products
  2. upload gallery to first simple product (will be needed to test gallery reload)
  3. go to product page, click on 1st swatch

Expected result

  1. gallery of first simple product should be loaded

Actual result

  1. JS error
    Trace:
    swatch-renderer.js:694 Uncaught TypeError: Cannot read property 'oldPrice' of undefined
    at $.(anonymous function).(anonymous function)._UpdatePrice (http://magento213.loc/pub/static/version1482569607/frontend/Magento/luma/en_US/Magento_Swatches/js/swatch-renderer.js:694:23)
    at $.(anonymous function).(anonymous function)._UpdatePrice (http://magento213.loc/pub/static/version1482569607/frontend/Magento/luma/en_US/jquery/jquery-ui.js:402:25)
    at $.(anonymous function).(anonymous function)._OnClick (http://magento213.loc/pub/static/version1482569607/frontend/Magento/luma/en_US/Magento_Swatches/js/swatch-renderer.js:532:25)
    at $.(anonymous function).(anonymous function)._OnClick (http://magento213.loc/pub/static/version1482569607/frontend/Magento/luma/en_US/jquery/jquery-ui.js:402:25)
    at HTMLDivElement. (http://magento213.loc/pub/static/version1482569607/frontend/Magento/luma/en_US/Magento_Swatches/js/swatch-renderer.js:482:32)
    at HTMLDivElement.dispatch (http://magento213.loc/pub/static/version1482569607/frontend/Magento/luma/en_US/jquery.js:4624:9)
    at HTMLDivElement.elemData.handle (http://magento213.loc/pub/static/version1482569607/frontend/Magento/luma/en_US/jquery.js:4292:28)
    image
  2. Notes:
    2.1. if I click on next swatch (color), error is not occurred (in other words when all options/swatches are chosen)
    2.2. there was no such error on 2.1.2
@ashsmith
Copy link

I'm also getting this after upgrading a client from 2.1.2 to 2.1.3.

From playing around a light bit of debugging, I've found the following lines were introduced in 2.1.3, and is where the error comes from. result is undefined when these lines are executed.

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

Taking a look a what result is:

result = $widget.options.jsonConfig.optionPrices[_.findKey($widget.options.jsonConfig.index, options)];

Now, the reason why this returns undefined is because none of the options match $widget.options.jsonConfig.index. This is because (in my case) there was one option not yet selected. options looks like this: {187: undefined, 191: "1443"}. Whereas, it is expected for both items to have values.

My (current) solution, to get around this, is to override in the theme, and abort before code mentioned above is executed. Which looks like this:

if (!result) {
    return;
}

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

Of course, this means the state of this.options.slyOldPriceSelector is never changed, which in my use case, as it stands is fine.

This is specific commit, which includes links to the github tickets it was resolving: eb2ec29

@ghost
Copy link

ghost commented Jan 15, 2017

@ashsmith workaround did the job for me.

@petterkj
Copy link
Contributor

petterkj commented Feb 8, 2017

Confirmed. 2.1.4.

2 user selectable attributes.

In my case, Color (swatch) size (dropdown).

If you only select swatch, JS error (and product image does not change)...

BUT if you select dropdown AND then swatch, no JS error.. And it changes product image..

Tested in environment: production.

@mcspronko
Copy link
Contributor

Can't reproduce on current magento:develop branch.

@mpont91
Copy link

mpont91 commented Mar 4, 2017

Installed a fresh magento 2.1.5 via bitnami VM magento stack, with sample data:

capture

@martynshanks
Copy link

martynshanks commented Mar 14, 2017

Same issue Magento 2.1.5 download from Github

screen shot 2017-03-14 at 09 45 16

adding the code snippet about worked for me too
/vendor/magento/module-swatches/view/frontend/web/js (line 714)

` if (!result) {
return;
}

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

@thdoan
Copy link

thdoan commented Apr 3, 2017

We just upgraded to v2.1.5 and can still reproduce this issue.

@refaelgold
Copy link

Same here 👎

@blizam
Copy link

blizam commented Apr 10, 2017

same issue... just posting so I can watch this issue

Also, this is ALWAYS an issue in Configurable products where no attribute can be defaulted thus all options have no values on page load

crantron pushed a commit to crantron/magento2 that referenced this issue Apr 12, 2017
@thdoan
Copy link

thdoan commented Apr 17, 2017

Another quick fix:

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

@blizam
Copy link

blizam commented Apr 18, 2017

I tested crantron@a84852b and the price is not updating as options are selected/even after all options are selected... I have both swatches and normal dropdown attributes on my configurable product

EDIT: it was a by-product of me moving the product.info.price element to a different area of the page... would by nice if the JS worked for changing the price regardless of where the price is rendered... though it does occur to me that form elements might not work so well outside the form :)

@LCIJJ
Copy link

LCIJJ commented Apr 28, 2017

Confirming this issue still occurs on 2.1.6, environment: default.

Clicking color swatch doesn't update product image. It's not until after clicking the size, associated product image updates. Using Chrome developer console, JS error (Uncaught TypeError: Cannot read property 'oldPrice' of undefined) triggers each time a swatch is clicked. See screenshot for full error>>> https://www.screencast.com/t/fXpFIEo4

Posting to follow.

@vkranjith
Copy link
Contributor

Hi Magento Team,
I would like to work on it.

@dreamworkers
Copy link

Hi, @OZZlE and I will work on it.

@dreamworkers
Copy link

Fixed with: 269c215

@okorshenko
Copy link
Contributor

okorshenko commented May 29, 2017

@dreamworkers thank you for research. Could you please apply the fix 269c215 (which was done for develop branch) for 2.1-develop branch, verify it and create Pull Request to 2.1-develop branch

Thank you

dreamworkers pushed a commit to dreamworkers/magento2 that referenced this issue May 29, 2017
magento-team pushed a commit that referenced this issue Jun 1, 2017
…ned oldPrice #9776

 - Merge Pull Request #9776 from dreamworkers/magento2:fix/7959-oldprice-swatchrenderer
magento-team pushed a commit that referenced this issue Jun 1, 2017
[EngCom] Public Pull Requests - 2.1
 - MAGETWO-69541: #7959 - Fix for JS error on Swatch Renderer for undefined oldPrice #9776
@ihor-sviziev
Copy link
Contributor

Looks like this issue was already fixed in develop & 2.1-develop branches. I think we need to close it.

@okorshenko
Copy link
Contributor

@ihor-sviziev thank you for your comment

@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-69541

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Catalog Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests