11 use Magento\Directory\Model\AllowedCountriesFactory;
22 private $moduleDataSetup;
27 private $storeManager;
32 private $allowedCountries;
45 $this->moduleDataSetup = $moduleDataSetup;
47 $this->allowedCountries = $allowedCountries;
55 $this->moduleDataSetup->getConnection()->beginTransaction();
58 $this->migrateStoresAllowedCountriesToWebsite();
59 $this->moduleDataSetup->getConnection()->commit();
60 }
catch (\Exception $e) {
61 $this->moduleDataSetup->getConnection()->rollBack();
71 private function migrateStoresAllowedCountriesToWebsite()
73 $allowedCountries = [];
75 foreach ($this->storeManager->getStores() as
$store) {
76 $allowedCountries = $this->mergeAllowedCountries(
83 foreach ($this->storeManager->getWebsites() as
$website) {
84 $allowedCountries = $this->mergeAllowedCountries(
91 $connection = $this->moduleDataSetup->getConnection();
95 $this->moduleDataSetup->getTable(
'core_config_data'),
103 foreach ($allowedCountries as $scopeId => $countries) {
105 $this->moduleDataSetup->getTable(
'core_config_data'),
107 'value' => implode(
',', $countries)
111 'scope_id = ?' => $scopeId,
125 private function getAllowedCountries($scope, $scopeCode)
127 return $this->allowedCountries->makeCountriesUnique(
128 $this->allowedCountries->getCountriesFromConfig($scope, $scopeCode)
140 private function mergeAllowedCountries(array $countries, array $newCountries, $identifier)
142 if (!isset($countries[$identifier])) {
143 $countries[$identifier] = $newCountries;
145 $countries[$identifier] = array_replace($countries[$identifier], $newCountries);
157 UpdateAutocompleteOnStorefrontConfigPath::class
__construct(ModuleDataSetupInterface $moduleDataSetup, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Directory\Model\AllowedCountries $allowedCountries)
const ALLOWED_COUNTRIES_PATH