Magento2: M2.2.3 Checkout - Once integer is stored for State/Province field, it can not be changed to alphanumeric

Created on 12 Mar 2018  路  12Comments  路  Source: magento/magento2


Preconditions


  1. Magento 2.2.3 with sample data, installed via composer, fresh installation.
  2. PHP 7.0.27-0+deb9u1, mysqld Ver 10.1.26-MariaDB-0+deb9u1

Steps to reproduce

  1. Put item in cart. Go to checkout.
  2. Select Country without prepoulated list of State/Provinces.
  3. Enter integer value in State/Province field. (E.g. "1").
  4. Fill in the rest of the forms with mock data.
  5. Continue and click "Place Order".
  6. Receive error message (status 400): _"Please check the shipping address information. Invalid value of "1" provided for the regionId field."_
  7. Step back, enter "AlphaNumeric" data into State/Province field.
  8. Continue and click "Place Order"

Expected result

  1. Order should be placed.

Actual result

  1. Error (status 400) again, _"Please check the shipping address information. Invalid value of "1" provided for the regionId field."_

Thoughts

It appears that once an integer is stored for the user's session in the State/Province field, it can no longer be changed to AlphaNumeric data. Similar, if one steps back, select e.g. United States and state number 3 on the dropdown, and then back to a country without prepopulated States/Provinces, and enter some Alphanumeric data, it still returns an error, and says "3" is not a valid value for this field.

Checkout mmit18 Fixed in 2.3.x Clear Description Confirmed Format is valid Reproduced on 2.2.x

Most helpful comment

@magento-engcom-team great can you point to parts of the code where it was fixed , so extension devs could backport or suggest hotfix to customers before 2.3.0 is out and patch released

All 12 comments

@eskilh, thank you for your report.
The issue is already fixed in 2.3.0
But we will consider to backport the fix to patch releases

@magento-engcom-team great can you point to parts of the code where it was fixed , so extension devs could backport or suggest hotfix to customers before 2.3.0 is out and patch released

I'm working on it #dmcdindia

mmit18

@s-pistore thank you for joining. Please accept team invitation here and self-assign the issue.

The issue seems to be present also in 2.3-develop.
Digging in the core i think the issue is related to $quote->collectTotals() in /app/code/Magento/Quote/Model/QuoteRepository/SaveHandler.php.

It calls (after many calls) /app/code/Magento/Tax/Model/Sales/Total/Quote/CommonTaxCollector.php where in mapAddress() has $address->getRegionId().

Finally in /app/code/Magento/Customer/Model/Address/AbstractAddress.php in getRegionId() there is the issue.

Here, like the issue described, it checks

...
if (!$regionId) {
    if (is_numeric($region)) {
        $this->setData('region_id', $region);
        $this->unsRegion();
    } else {
        ...
    }
}
...

So if customer insert an integer in State/Province field (region) it will be copied in region_id and this trig the error.

I could fix the issue, but before to proceed i'm waiting that my suppositions are confirmed from magento team.

@magento-engcom-team You're not prioritising releasing a backport patch for a checkout breaking issue?

Can reproduce it on 2.2-develop and 2.3-develop.

Hi there good people! I came up with a quick fix for this terrible checkout-breaking bug.

The quick-fix is at the line 650: https://gist.github.com/ivancukns/70cbff6d0128220ec72b336fe2d2e505

I added this piece of code "!empty($allowedRegions)" in the if statement. The reason I did this is because the variable $allowedRegions is always an empty array in cases when a country which doesnt have a selection of regions for choosing is selected by users.

This elseif is checking if the region_id is in_array, but the array is empty in these cases and will always trigger the error. Also, I believe that regions collection does not exist for countries for which users have to type the name of their region, so this elseif only has sense for countries with region collections, otherwise it is always triggering the error.

I hope this helps someone!

Cheers

It's really not fine. I cannot move to magento 2.3 and need the fix. It should not be like each time moving to the new version of magento to fix a specific bug. So what was the fix guys. I get that error with customer login not on the checkout page.

Hi @TomashKhamlai. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:

  • [x] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [x] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.

The issue was re-tested and we can confirm that it was fixed on the 2.3 release branch. We closing this issue as fixed due to upcoming 2.3 release that will be available soon.

Was this page helpful?
0 / 5 - 0 ratings