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.53k stars 9.31k forks source link

Region not visible on Checkout page #38440

Open schnere opened 8 months ago

schnere commented 8 months ago

Preconditions and environment

Steps to reproduce

Add a product in US substore to cart, go to checkout shipping page.

Expected result

For US substore the region field should be displayed in checkout because the field is required.

Actual result

The region field is hidden.

Additional information

The problem is that the options for both countries are set to is_default. The issue is caused in this line: https://github.com/magento/magento2/blob/594a590b6f3821d49a3ecc98d5c4d5336a0b4d04/app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php#L303

The region element then only checks the first country it finds with is_default set: https://github.com/magento/magento2/blob/594a590b6f3821d49a3ecc98d5c4d5336a0b4d04/app/code/Magento/Ui/view/base/web/js/form/element/region.js#L34

As DE is in alphabetical order before US this option will be used which causes the region field to be hidden.

Release note

No response

Triage and priority

m2-assistant[bot] commented 8 months ago

Hi @schnere. 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. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

schnere commented 8 months ago

This patch solves the problem in my case:

diff --git a/vendor/magento/module-directory/Model/ResourceModel/Country/Collection.php b/vendor/magento/module-directory/Model/ResourceModel/Country/Collection.php
index d84b11fc..545db027 100644
--- a/vendor/magento/module-directory/Model/ResourceModel/Country/Collection.php
+++ b/vendor/magento/module-directory/Model/ResourceModel/Country/Collection.php
@@ -293,19 +293,14 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
      */
     private function addDefaultCountryToOptions(array &$options)
     {
-        $defaultCountry = [];
-        foreach ($this->storeManager->getWebsites() as $website) {
-            $defaultCountryConfig = $this->_scopeConfig->getValue(
-                \Magento\Directory\Helper\Data::XML_PATH_DEFAULT_COUNTRY,
-                ScopeInterface::SCOPE_WEBSITES,
-                $website
-            );
-            $defaultCountry[$defaultCountryConfig][] = $website->getId();
-        }
+        $defaultCountry = $this->_scopeConfig->getValue(
+            \Magento\Directory\Helper\Data::XML_PATH_DEFAULT_COUNTRY,
+            ScopeInterface::SCOPE_STORE
+        );

         foreach ($options as $key => $option) {
-            if (isset($defaultCountry[$option['value']])) {
-                $options[$key]['is_default'] = !empty($defaultCountry[$option['value']]);
+            if ($defaultCountry == $option['value']) {
+                $options[$key]['is_default'] = true;
             }
         }
     }
m2-assistant[bot] commented 8 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 8 months ago

Hello @schnere,

Thank you for the report and collaboration!

Verified this issue on 2.4-develop. When the base store is set to DE where region is made hidden, and the sub store set to US with region as required. In the checkout page of sub store the region was not displayed.

Please take a look at the screenshot below:

image

Here it can be seen that region/state field is absent.

Hence confirming this issue.

Thank you.

github-jira-sync-bot commented 8 months ago

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

m2-assistant[bot] commented 8 months ago

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