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

Fix JS error on cart from postcode validation when 'US' is deselected as an allowed country #13051

Merged
merged 1 commit into from
Jan 9, 2018

Conversation

codekipple
Copy link

Description

On the cart page the postcode validation can cause a JS error Uncaught TypeError: Cannot read property 'is_zipcode_optional' of undefined.
screen shot 2018-01-08 at 10 23 47

To get this error the Magento store has to have deselected 'United States' in the 'Allowed Countries' admin option. Select any country except 'United States' as the default country:- Admin -> Stores -> configuration -> General -> Default Country

If this is the case then Magento will actually cycle through the update() method in app/code/Magento/Ui/view/base/web/js/form/element/region.js twice. Once with the two letter code for the country selected as the 'Default Country' and once with the 'US' country code regardless ofwhether the 'United States' is selected as the default country. If the 'United States' is deselected in the 'Allowed Countries' when the update() method in region.js runs using a value of 'US' the 'option' variable in the update() method is undefined. This code checks for this scenario and returns early.

Manual testing scenarios

  1. Create a Store using Magento 2.2.2
  2. Select any country except 'United States' as the default country:- Admin -> Stores -> configuration -> General -> Default Country
  3. Deselect 'United States' in the 'Allowed Countries' option:- Admin -> Stores -> configuration -> General -> Allow Countries.
    screen shot 2018-01-08 at 10 26 05
  4. Add a product to cart and visit the cart page
  5. Open up your browsers inspect tool to see the JS error

…tion' is undefined. This can happen with stores that have a different deault country than US
@lbetineli
Copy link

I realized this today here in my magento 2.2.2.

I was wondering why the code goes into "update" method twice and the last one is always the "US" value...

@ishakhsuvarov ishakhsuvarov self-assigned this Jan 9, 2018
@ishakhsuvarov ishakhsuvarov added this to the January 2018 milestone Jan 9, 2018
magento-team pushed a commit that referenced this pull request Jan 9, 2018
@magento-team magento-team merged commit c8ff538 into magento:2.2-develop Jan 9, 2018
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.

4 participants