@@ -66,6 +66,10 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
66
66
* @since 100.1.0
67
67
*/
68
68
protected $ countriesWithNotRequiredStates ;
69
+ /**
70
+ * @var \Magento\Store\Model\StoreManagerInterface
71
+ */
72
+ protected $ storeManager ;
69
73
70
74
/**
71
75
* Initialize dependencies.
@@ -80,6 +84,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
80
84
* @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils
81
85
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
82
86
* @param \Magento\Framework\App\Helper\AbstractHelper $helperData
87
+ * @param \Magento\Store\Model\StoreManagerInterface $storeManager
83
88
* @param array $countriesWithNotRequiredStates
84
89
* @param mixed $connection
85
90
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
@@ -96,6 +101,7 @@ public function __construct(
96
101
\Magento \Framework \Stdlib \ArrayUtils $ arrayUtils ,
97
102
\Magento \Framework \Locale \ResolverInterface $ localeResolver ,
98
103
\Magento \Framework \App \Helper \AbstractHelper $ helperData ,
104
+ \Magento \Store \Model \StoreManagerInterface $ storeManager ,
99
105
array $ countriesWithNotRequiredStates = [],
100
106
\Magento \Framework \DB \Adapter \AdapterInterface $ connection = null ,
101
107
\Magento \Framework \Model \ResourceModel \Db \AbstractDb $ resource = null
@@ -107,6 +113,7 @@ public function __construct(
107
113
$ this ->_countryFactory = $ countryFactory ;
108
114
$ this ->_arrayUtils = $ arrayUtils ;
109
115
$ this ->helperData = $ helperData ;
116
+ $ this ->storeManager = $ storeManager ;
110
117
$ this ->countriesWithNotRequiredStates = $ countriesWithNotRequiredStates ;
111
118
}
112
119
@@ -273,6 +280,15 @@ public function toOptionArray($emptyLabel = ' ')
273
280
$ sort = [$ name => $ foregroundCountry ] + $ sort ;
274
281
}
275
282
$ isRegionVisible = (bool )$ this ->helperData ->isShowNonRequiredState ();
283
+ $ defaultCountry = [];
284
+ foreach ($ this ->storeManager ->getWebsites () as $ website ) {
285
+ $ defaultCountryConfig = $ this ->_scopeConfig ->getValue (
286
+ \Magento \Directory \Helper \Data::XML_PATH_DEFAULT_COUNTRY ,
287
+ ScopeInterface::SCOPE_WEBSITES ,
288
+ $ website
289
+ );
290
+ $ defaultCountry [$ defaultCountryConfig ][] = $ website ->getId ();
291
+ }
276
292
$ options = [];
277
293
foreach ($ sort as $ label => $ value ) {
278
294
$ options = $ this ->addForegroundCountriesToOptionArray ($ emptyLabel , $ options );
@@ -285,6 +301,9 @@ public function toOptionArray($emptyLabel = ' ')
285
301
if ($ this ->helperData ->isZipCodeOptional ($ value )) {
286
302
$ option ['is_zipcode_optional ' ] = true ;
287
303
}
304
+ if (isset ($ defaultCountry [$ value ])) {
305
+ $ option ['is_default ' ] = $ defaultCountry [$ value ];
306
+ }
288
307
$ options [] = $ option ;
289
308
}
290
309
if ($ emptyLabel !== false && count ($ options ) > 0 ) {
0 commit comments