File tree Expand file tree Collapse file tree 1 file changed +25
-9
lines changed
app/code/Magento/Directory/Model/ResourceModel/Country Expand file tree Collapse file tree 1 file changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -269,18 +269,15 @@ public function addCountryIdFilter($countryId)
269
269
public function toOptionArray ($ emptyLabel = ' ' )
270
270
{
271
271
$ 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
+
279
274
$ this ->_arrayUtils ->ksortMultibyte ($ sort , $ this ->_localeResolver ->getLocale ());
280
275
foreach (array_reverse ($ this ->_foregroundCountries ) as $ foregroundCountry ) {
281
276
$ 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
+ }
284
281
}
285
282
$ isRegionVisible = (bool )$ this ->helperData ->isShowNonRequiredState ();
286
283
@@ -366,4 +363,23 @@ public function getCountriesWithRequiredStates()
366
363
}
367
364
return $ countries ;
368
365
}
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
+ }
369
385
}
You can’t perform that action at this time.
0 commit comments