Skip to content

Commit 9031354

Browse files
MAGETWO-99424: "0" in country dropdown list when allowed countries differs from top destinations
1 parent 72aebb7 commit 9031354

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,18 +269,15 @@ public function addCountryIdFilter($countryId)
269269
public function toOptionArray($emptyLabel = ' ')
270270
{
271271
$options = $this->_toOptionArray('country_id', 'name', ['title' => 'iso2_code']);
272-
$sort = [];
273-
foreach ($options as $data) {
274-
$name = (string)$this->_localeLists->getCountryTranslation($data['value']);
275-
if (!empty($name)) {
276-
$sort[$name] = $data['value'];
277-
}
278-
}
272+
$sort = $this->getSort($options);
273+
279274
$this->_arrayUtils->ksortMultibyte($sort, $this->_localeResolver->getLocale());
280275
foreach (array_reverse($this->_foregroundCountries) as $foregroundCountry) {
281276
$name = array_search($foregroundCountry, $sort);
282-
unset($sort[$name]);
283-
$sort = [$name => $foregroundCountry] + $sort;
277+
if ($name) {
278+
unset($sort[$name]);
279+
$sort = [$name => $foregroundCountry] + $sort;
280+
}
284281
}
285282
$isRegionVisible = (bool)$this->helperData->isShowNonRequiredState();
286283

@@ -366,4 +363,23 @@ public function getCountriesWithRequiredStates()
366363
}
367364
return $countries;
368365
}
366+
367+
/**
368+
* Get sort
369+
*
370+
* @param array $options
371+
* @return array
372+
*/
373+
private function getSort(array $options): array
374+
{
375+
$sort = [];
376+
foreach ($options as $data) {
377+
$name = (string)$this->_localeLists->getCountryTranslation($data['value']);
378+
if (!empty($name)) {
379+
$sort[$name] = $data['value'];
380+
}
381+
}
382+
383+
return $sort;
384+
}
369385
}

0 commit comments

Comments
 (0)