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