magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.51k stars 9.31k forks source link

[Issue] Bug Fix: Missing region on shipping with some saved addresses #34493

Open m2-assistant[bot] opened 2 years ago

m2-assistant[bot] commented 2 years ago

This issue is automatically created based on existing pull request: magento/magento2#34482: Bug Fix: Missing region on shipping with some saved addresses


Description (*)

When shipping using a saved address outside of the US/CA the dest_region_code is empty. For example a saved address in the UK will expose the problem. I traced the issue back to the Customer\Model\Address\AbstractAddress class's getRegionCode method.

getRegionCode assumes there will be a valid region_id - which there isn't in this case - or that the region field will be a usable string instead. However when converting the saved address into a quote address the region field is parsed as an associative array with three parts - region, region_code, and region_id. So in this case getRegionCode needs an additional check to use $region['region_code'] if available.

I've added a test to expose the problem and prove the fix. The test is Magento\Customer\Test\Unit\Model\Address\AbstractAddressTest::testGetRegionCodeWithRegionArray

Fixed Issues (if relevant)

I've not raised a separate issue, I'm using this PR as the bug report

Manual testing scenarios (*)

I've provided a unit test that exposes the problem

This cannot be fully seen in the store's checkout with the builtin shipping methods as none of them support region based shipping outside the US/CA. It does impact 3rd party shipping extensions however.

To manually test you'll have to use the debugger to view the details of the RateRequest when it's passed to one of the shipping carriers. For example put a breakpoint at the top of Magento\OfflineShipping\Model\Carrier\Flatrate::collectRates

Expected: "Essex" Actual: null

Questions or comments

There is an unrelated test that was failing for me before I made my changes. All tests related to shipping and address handling including my new test pass.

Contribution checklist (*)

m2-assistant[bot] commented 2 years ago

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Hotel commented 2 years ago

Hello @TravisBernard,

We have tried to reproduce the issue in Magento 2.4-develop branch and the issue is reproducible for us. We have a registered user with both US and UK address. For US address region information is present but fir UK address region is shown as null. Please refer the below screenshot for reference:

For US Address

image

For UK Address

image

Hence confirming the issue.

Thanks

github-jira-sync-bot commented 2 years ago

:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-2831 is successfully created for this GitHub issue.

m2-assistant[bot] commented 2 years ago

:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.