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.5k stars 9.3k forks source link

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

Closed m2-assistant[bot] closed 6 months 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 (*)

Resolved issues:

  1. [x] resolves magento/magento2#34493: Bug Fix: Missing region on shipping with some saved addresses
m2-assistant[bot] commented 6 months ago

Hi @engcom-November. 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-November commented 6 months ago

As this issue has been already confirmed here, closing this issue as duplicate. Thank you.