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.57k stars 9.32k forks source link

Error saving new address in address book for customer with Share Customer Accounts enabled #39348

Closed alessandrogrisafi closed 1 week ago

alessandrogrisafi commented 2 weeks ago

Preconditions and environment

Steps to reproduce

Expected result

Order is placed

Actual result

Placing the order appears the errore Invalid value of "GB" provided for the countryId field.

Additional information

The issue arises because, when saving a new address in \Magento\Customer\Model\ResourceModel\AddressRepository::save, the store ID of the address is set to match the customer’s store ID:

    $addressModel->setStoreId($customerModel->getStoreId());

During validation in \Magento\Customer\Model\Address\Validator\Country::validateCountry, an address in the UK (with country code GB) fails validation. This happens because validateCountry checks the list of allowed countries based on the store ID associated with the address, which is inherited from the customer. In this example the customer is associated with the Italian store (IT) so the address will also use this store ID, resulting in a list of allowed countries that does not include the UK (GB). Consequently, the UK address is invalid and the order cannot be placed

Release note

No response

Triage and priority

m2-assistant[bot] commented 2 weeks ago

Hi @alessandrogrisafi. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.

m2-assistant[bot] commented 2 weeks ago

Hi @engcom-Bravo. 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-Bravo commented 1 week ago

Hi @alessandrogrisafi,

Thanks for your reporting and collaboration.

We have verified the issue in Latest 2.4-develop instance and the issue is not reproducible.Kindly refer the screenshots.

Steps to reproduce

Order-5000000001-11-13-2024_10_26_AM

We are able to place the order in the UK Store.

Kindly recheck the issue in Latest 2.4-develop instance and elaborate the steps to reproduce if the issue is still reproducible.

Thanks.

alessandrogrisafi commented 1 week ago

Hi,

We're currently using Magento version 2.4.5, as specified in the first comment, rather than the latest 2.4-develop instance (which I assume is version 2.4.7). I've replicated the issue on a vanilla Magento 2.4.5 setup.

Could you please attempt to replicate the issue on Magento 2.4.5 following the same steps?

Additionally, I originally overlooked a minor configuration detail: the IT and UK stores have their Default Country settings set to Italy and the United Kingdom, respectively.

image image

Thank you!

engcom-Bravo commented 1 week ago

Hi @alessandrogrisafi,

Thanks for your update.

It is recommended to verify the issue in Latest 2.4-develop instance as it is having latest codebase.Could you please verify the issue in Latest Magento instance and elaborate the steps to reproduce if the issue is still reproducible.

Thanks.

alessandrogrisafi commented 1 week ago

Hi,

We had a similar discussion with the Adobe Enterprise Support Team, and after several iterations, we identified that the key factor in reproducing the bug is not just creating two different stores, but ensuring that the stores are under different websites as well.

Using this setup, they were able to reproduce the issue in Magento 2.4.5-p10. The bug appears to be resolved in Magento 2.4.7-p3, and they are now working on creating a patch for Magento 2.4.5-p10 to address the issue in the same way it was fixed in Magento 2.4.7-p3.

Thank you for your support. This issue can now be closed.