Closed m2-assistant[bot] closed 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:
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to.2.4-develop
branch@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure. 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.Issue: Confirmed
once verification is complete. As this issue has been already confirmed here, closing this issue as duplicate. Thank you.
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 theregion
field will be a usable string instead. However when converting the saved address into a quote address theregion
field is parsed as an associative array with three parts -region
,region_code
, andregion_id
. So in this casegetRegionCode
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
Essex
.$request->getDestRegionCode()
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: