Magento2: Customer Address Country Options

Created on 22 Oct 2019  路  31Comments  路  Source: magento/magento2

Triage Note

  • The issue is reproducible on 2.3.3 release version
  • The issue is NOT reproducible on 2.3-develop
  • 2.3.3 is not merged into 2.3-develop at this moment

Preconditions (*)

  1. 2.3.3

Steps to reproduce (*)

  1. Install new Magento 2.3.3
  2. Set "Default Country" to Austria
  3. Set "Allow Countries" to Austria and Germany
  4. Add new customer in admin view and save
  5. Click "Add new Address" in customer view

Expected result (*)

  1. Country select should contain Austria and Germany

Actual result (*)

  1. Country select contains Afghanistan and 脜land Islands
    2.country
Backend Customer Clear Description Confirmed Format is valid Ready for Work Reproduced on 2.3.x

Most helpful comment

This is the commit that fixed the issue for me.
https://github.com/magento/magento2/commit/7211d50998f786dce0628346439649ac8d196c46

Seems to be in 2.3-develop but not in the 2.3.3 release

All 31 comments

Hi @bernd-reindl. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@bernd-reindl do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

I'm getting same issue with magento 2.3.3; in my case default country is US, allowed countries are US, CA but in admin customer address add/edit form the countries list has Albania, Afghanistan

Hi @krishprakash. 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:

  • [x] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [x] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [x] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [x] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [x] 5. Add label Issue: Confirmed once verification is complete.

  • [x] 6. Make sure that automatic system confirms that report has been added to the backlog.

@krishprakash Are you working on this issue?

@magento give me 2.3.3 instance

Hi @krishprakash. Thank you for your request. I'm working on Magento 2.3.3 instance for you

Hi @krishprakash, here is your Magento instance.
Admin access: https://i-25218-2-3-3.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@magento give me 2.3-develop instance

Hi @krishprakash. Thank you for your request. I'm working on Magento 2.3-develop instance for you

Hi @krishprakash, here is your Magento instance.
Admin access: https://i-25218-2-3-develop.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

:white_check_mark: Confirmed by @krishprakash
Thank you for verifying the issue. Based on the provided information internal tickets MC-22023 were created

Issue Available: @krishprakash, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._

Same issue here on our 2.3.3 installation.

Schermafbeelding 2019-10-23 om 12 56 35

This is the commit that fixed the issue for me.
https://github.com/magento/magento2/commit/7211d50998f786dce0628346439649ac8d196c46

Seems to be in 2.3-develop but not in the 2.3.3 release

@BrentRobert Thanks! Works perfectly :)

Magento - how can such a major bug be introduced when you have several weeks of QA?!?!?!

I have the same issue too - Whats the best way to fix it without editing core files directly if Magento is not going to release a fix

@jamie-selesti Create a composer patch and update your composer.json to use it. Next time you run composer install it will be applied.

rparsi-boxycharm, can you tell me how to do so? I'm not sure what you mean by composer patch. Where do we download this?

@chichitsai0517 You would use an IDE to generate the patch file (ie phpstorm). Alternatively, you can just override the target file in your custom admin theme.
Magento_Customer/view/adminhtml/ui_component/customer_address_form.xml

Copy above file to your custom admin theme and modify the country <select> tag, to look like this

<select>
        <settings>
                <options class="Magento\Directory\Model\ResourceModel\Country\Collection"/>
        </settings>
</select>

rparsi-boxycharm, can you tell me how to do so? I'm not sure what you mean by composer patch. Where do we download this?

https://devdocs.magento.com/guides/v2.3/comp-mgr/patching.html

Another article on how to create/apply patches: https://www.classyllama.com/blog/create-apply-patches-magento-2

Protip: you can append .patch to a Github commit or PR to get a diff that can be used as a patch. e.g., https://github.com/magento/magento2/commit/7211d50998f786dce0628346439649ac8d196c46.patch (you would need to remove the app/code/Magento/Customer/ strings in that patch to get it to apply using composer-patches)

Hello All, i have resolve this issue with the following step for the if from store configuration we set multiple country as allowed country.

this is the steps :

1) ovverride the vendor/magento/module-customer/view/adminhtml/ui_component/customer_address_form.xml this file with the new source class with : MagentoDirectoryModelResourceModelCountryCollection => MagentoDirectoryModelConfigSourceCountry

2) override the vendor/magento/module-directory/Helper/Data.php file with newly added const variable : const XML_PATH_DEFAULT_ALLOW = 'general/country/allow';

3) used that XML_PATH_DEFAULT_ALLOW variable in the following ovverride file :
MagentoDirectoryModelResourceModelCountryCollection.php
create new function :

/**
* Adds allowed country to options
*
* @param array $options
* @return void
*/
public function addAllowedCountryToOptions(array &$options)
{
$defaultCountry = [];
foreach ($this->storeManager->getWebsites() as $website) {
$defaultCountryConfig = $this->_scopeConfig->getValue(
MagentoDirectoryHelperData::XML_PATH_DEFAULT_ALLOW,
ScopeInterface::SCOPE_WEBSITES,
$website
);
$defaultCountry[$defaultCountryConfig][] = $website->getId();
}

    foreach ($options as $key => $option) {
        if (isset($defaultCountry[$option['value']])) {
            $options[$key]['is_default'] = !empty($defaultCountry[$option['value']]);
        }
    }
}

4) final step ovverride the : MagentoDirectoryModelConfigSourceCountry.php file
add MagentoFrameworkAppRequestHttp $request this in the construct

and add the following code in to the toOptionArray($isMultiselect = false, $foregroundCountries = '') function in that file

$moduleName = $this->_request->getModuleName();
$controller = $this->_request->getControllerName();
$action = $this->_request->getActionName();
$route = $this->_request->getRouteName();
if (!$this->_options) {
if($moduleName == 'admin' && $controller == 'system_config' && $action == 'edit'){
$this->_options = $this->_countryCollection->loadData()->setForegroundCountries(
$foregroundCountries
)->toOptionArray(
false
);
} else {
$this->_options = $this->_countryCollection->loadByStore()->setForegroundCountries($foregroundCountries)->toOptionArray(false);
}
}

this steps solve the issue for the multiple allowed country from system configuration but i am still try to set the code for the if only single country select then it gives blank.

if anybody find that solution then please let me know.

Triage Note

  • The issue is reproducible on 2.3.3 release version
  • The issue is NOT reproducible on 2.3-develop
  • 2.3.3 is not merged into 2.3-develop at this moment

Preconditions (*)

  1. 2.3.3

Steps to reproduce (*)

  1. Install new Magento 2.3.3
  2. Set "Default Country" to Austria
  3. Set "Allow Countries" to Austria and Germany
  4. Add new customer in admin view and save
  5. Click "Add new Address" in customer view

Expected result (*)

  1. Country select should contain Austria and Germany

Actual result (*)

  1. Country select contains Afghanistan and 脜land Islands
    2.country

please read my comment is solve your issue if you select the multi country from system configuration.

This is the commit that fixed the issue for me.
7211d50

Seems to be in 2.3-develop but not in the 2.3.3 release

Yes your soultion also work for signle and multion country if selected from store configuration.

The same issue exist in magento 2.3.2 version also.

@sdzhepa: since https://github.com/magento/magento2/commit/7211d50998f786dce0628346439649ac8d196c46 has been included in Magento 2.3.4, this issue can probably be closed? Can you double check?

@hostep i m not checked in 2.3.4 version for this issue

I upgraded to 2.3.4 and it has been fixed.

@chichitsai0517 thanks for the checking

Ok, then we should close this issue, thanks for testing @chichitsai0517 !

Was this page helpful?
0 / 5 - 0 ratings