@@ -66,6 +66,10 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
6666 * @since 100.1.0
6767 */
6868 protected $ countriesWithNotRequiredStates ;
69+ /**
70+ * @var \Magento\Store\Model\StoreManagerInterface
71+ */
72+ protected $ storeManager ;
6973
7074 /**
7175 * Initialize dependencies.
@@ -80,6 +84,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
8084 * @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils
8185 * @param \Magento\Framework\Locale\ResolverInterface $localeResolver
8286 * @param \Magento\Framework\App\Helper\AbstractHelper $helperData
87+ * @param \Magento\Store\Model\StoreManagerInterface $storeManager
8388 * @param array $countriesWithNotRequiredStates
8489 * @param mixed $connection
8590 * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
@@ -96,6 +101,7 @@ public function __construct(
96101 \Magento \Framework \Stdlib \ArrayUtils $ arrayUtils ,
97102 \Magento \Framework \Locale \ResolverInterface $ localeResolver ,
98103 \Magento \Framework \App \Helper \AbstractHelper $ helperData ,
104+ \Magento \Store \Model \StoreManagerInterface $ storeManager ,
99105 array $ countriesWithNotRequiredStates = [],
100106 \Magento \Framework \DB \Adapter \AdapterInterface $ connection = null ,
101107 \Magento \Framework \Model \ResourceModel \Db \AbstractDb $ resource = null
@@ -107,6 +113,7 @@ public function __construct(
107113 $ this ->_countryFactory = $ countryFactory ;
108114 $ this ->_arrayUtils = $ arrayUtils ;
109115 $ this ->helperData = $ helperData ;
116+ $ this ->storeManager = $ storeManager ;
110117 $ this ->countriesWithNotRequiredStates = $ countriesWithNotRequiredStates ;
111118 }
112119
@@ -273,6 +280,15 @@ public function toOptionArray($emptyLabel = ' ')
273280 $ sort = [$ name => $ foregroundCountry ] + $ sort ;
274281 }
275282 $ 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+ }
276292 $ options = [];
277293 foreach ($ sort as $ label => $ value ) {
278294 $ options = $ this ->addForegroundCountriesToOptionArray ($ emptyLabel , $ options );
@@ -285,6 +301,9 @@ public function toOptionArray($emptyLabel = ' ')
285301 if ($ this ->helperData ->isZipCodeOptional ($ value )) {
286302 $ option ['is_zipcode_optional ' ] = true ;
287303 }
304+ if (isset ($ defaultCountry [$ value ])) {
305+ $ option ['is_default ' ] = $ defaultCountry [$ value ];
306+ }
288307 $ options [] = $ option ;
289308 }
290309 if ($ emptyLabel !== false && count ($ options ) > 0 ) {
0 commit comments