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

#7959 - Fix for JS error on Swatch Renderer for undefined oldPrice #9776

Conversation

dreamworkers
Copy link

@dreamworkers dreamworkers commented May 29, 2017

This PR backports commit 269c215 (originally for -develop) for 2.1-develop and issue #7959.

Description

Check and verify if 'result' is defined or not before oldPrice is fetched from it.

Fixed Issues (if relevant)

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

Manual testing scenarios

  1. Follow the list of steps at the issue that is resolved here.

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented May 29, 2017

CLA assistant check
All committers have signed the CLA.

@okorshenko okorshenko self-assigned this May 29, 2017
@okorshenko okorshenko added this to the May 2017 milestone May 29, 2017
@ishakhsuvarov ishakhsuvarov requested review from zetlen and removed request for zetlen May 29, 2017 13:45
@@ -711,7 +711,7 @@ define([
}
);

if (result.oldPrice.amount !== result.finalPrice.amount) {
if (typeof result != 'undefined' && result.oldPrice.amount !== result.finalPrice.amount) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things about this:'

  1. Always use strict !== comparison rather than loose != comparison, since the coercion rules of the latter can be surprising.
  2. Under what circumstances would result not exist? Can we eliminate that circumstance?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why these questions weren't raised when the original fix 269c215 was implemented yet they slow down backporting.
Maybe @aholovan could provide the insights you're looking for?

P.S. To quote some guy reporting an issue here on GitHub, "It's unbelievable the effort you guys go to, to avoid fixing the issue."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeof always returns a string so it's not necessary or standard practice to use strict comparison

Copy link
Contributor

@aholovan aholovan Jun 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @OZZlE , you are right about unnecessary strict comparison.

@zetlen, 'result' is undefined before all of the swatches are selected. It was the issue as with oldPrice and also with tierPrices. (how to reproduce is described in #8923 pull request)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aholovan Thanks for the background. Making the result always present is a good idea, but it seems to be out of scope for this PR.

@korostii I look at a fairly random sample of pull requests; my schedule doesn't allow me to review every single one. I didn't notice that this was a backport, so that's on me!

As for strict comparison, it really is a standard practice in all cases. Linters in standard configuration will complain. But it's all right; in a later project, we'll use an automated tool to change all of these loose comparisons to strict ones. So I will approve this!

@okorshenko okorshenko modified the milestones: May 2017, June 2017 Jun 1, 2017
@magento-team magento-team merged commit 8e43515 into magento:2.1-develop Jun 1, 2017
magento-team pushed a commit that referenced this pull request Jun 1, 2017
magento-team pushed a commit that referenced this pull request Jun 1, 2017
[EngCom] Public Pull Requests - 2.1
 - MAGETWO-69541: #7959 - Fix for JS error on Swatch Renderer for undefined oldPrice #9776
@magento-team
Copy link
Contributor

@dreamworkers thank you for your contribution. Your Pull Request has been successfully merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants