From 80384fc5cbcb715e210422222feca07b8359053b Mon Sep 17 00:00:00 2001 From: alojua Date: Tue, 17 Jul 2018 16:29:54 +0200 Subject: [PATCH 1/3] [Fix] Do not modify current list of countries with require states during setup upgrade. Also mark getCountriesWithRequiredStates() as deprecated because is no longer needed --- .../ResourceModel/Country/Collection.php | 4 + .../Magento/Directory/Setup/InstallData.php | 11 -- .../Magento/Directory/Setup/UpgradeData.php | 144 ++++++++---------- app/code/Magento/Directory/etc/di.xml | 4 - 4 files changed, 69 insertions(+), 94 deletions(-) diff --git a/app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php b/app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php index eb2b7cef0b707..93a6149e10fcf 100644 --- a/app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php +++ b/app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php @@ -64,6 +64,8 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab private $allowedCountriesReader; /** + * @deprecated + * * @var string[] * @since 100.1.0 */ @@ -349,6 +351,8 @@ public function setForegroundCountries($foregroundCountries) } /** + * @deprecated use \Magento\Directory\Helper\Data::getCountriesWithStatesRequired() instead + * * Get list of countries with required states * * @return \Magento\Directory\Model\Country[] diff --git a/app/code/Magento/Directory/Setup/InstallData.php b/app/code/Magento/Directory/Setup/InstallData.php index 33c3ae4558e16..12c3fba214804 100644 --- a/app/code/Magento/Directory/Setup/InstallData.php +++ b/app/code/Magento/Directory/Setup/InstallData.php @@ -842,16 +842,5 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface 'value' => 1 ] ); - - $countries = $this->directoryData->getCountryCollection()->getCountriesWithRequiredStates(); - $setup->getConnection()->insert( - $setup->getTable('core_config_data'), - [ - 'scope' => 'default', - 'scope_id' => 0, - 'path' => Data::XML_PATH_STATES_REQUIRED, - 'value' => implode(',', array_keys($countries)) - ] - ); } } diff --git a/app/code/Magento/Directory/Setup/UpgradeData.php b/app/code/Magento/Directory/Setup/UpgradeData.php index 4ee9ea33673d7..f4e9c1206525d 100644 --- a/app/code/Magento/Directory/Setup/UpgradeData.php +++ b/app/code/Magento/Directory/Setup/UpgradeData.php @@ -32,7 +32,7 @@ public function __construct(Data $directoryData) } /** - * Upgrades data for Directry module. + * Upgrades data for Directory module. * * @param ModuleDataSetupInterface $setup * @param ModuleContextInterface $context @@ -41,10 +41,10 @@ public function __construct(Data $directoryData) public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { if (version_compare($context->getVersion(), '2.0.1', '<')) { - $this->addCountryRegions($setup, $this->getDataForCroatia()); + $this->addCountryRegions($setup, 'IN', $this->getDataForCroatia()); } if (version_compare($context->getVersion(), '2.0.2', '<')) { - $this->addCountryRegions($setup, $this->getDataForIndia()); + $this->addCountryRegions($setup, 'HR', $this->getDataForIndia()); } } @@ -56,27 +56,27 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface private function getDataForCroatia() { return [ - ['HR', 'HR-01', 'Zagrebačka županija'], - ['HR', 'HR-02', 'Krapinsko-zagorska županija'], - ['HR', 'HR-03', 'Sisačko-moslavačka županija'], - ['HR', 'HR-04', 'Karlovačka županija'], - ['HR', 'HR-05', 'Varaždinska županija'], - ['HR', 'HR-06', 'Koprivničko-križevačka županija'], - ['HR', 'HR-07', 'Bjelovarsko-bilogorska županija'], - ['HR', 'HR-08', 'Primorsko-goranska županija'], - ['HR', 'HR-09', 'Ličko-senjska županija'], - ['HR', 'HR-10', 'Virovitičko-podravska županija'], - ['HR', 'HR-11', 'Požeško-slavonska županija'], - ['HR', 'HR-12', 'Brodsko-posavska županija'], - ['HR', 'HR-13', 'Zadarska županija'], - ['HR', 'HR-14', 'Osječko-baranjska županija'], - ['HR', 'HR-15', 'Šibensko-kninska županija'], - ['HR', 'HR-16', 'Vukovarsko-srijemska županija'], - ['HR', 'HR-17', 'Splitsko-dalmatinska županija'], - ['HR', 'HR-18', 'Istarska županija'], - ['HR', 'HR-19', 'Dubrovačko-neretvanska županija'], - ['HR', 'HR-20', 'Međimurska županija'], - ['HR', 'HR-21', 'Grad Zagreb'] + 'HR-01' => 'Zagrebačka županija', + 'HR-02' => 'Krapinsko-zagorska županija', + 'HR-03' => 'Sisačko-moslavačka županija', + 'HR-04' => 'Karlovačka županija', + 'HR-05' => 'Varaždinska županija', + 'HR-06' => 'Koprivničko-križevačka županija', + 'HR-07' => 'Bjelovarsko-bilogorska županija', + 'HR-08' => 'Primorsko-goranska županija', + 'HR-09' => 'Ličko-senjska županija', + 'HR-10' => 'Virovitičko-podravska županija', + 'HR-11' => 'Požeško-slavonska županija', + 'HR-12' => 'Brodsko-posavska županija', + 'HR-13' => 'Zadarska županija', + 'HR-14' => 'Osječko-baranjska županija', + 'HR-15' => 'Šibensko-kninska županija', + 'HR-16' => 'Vukovarsko-srijemska županija', + 'HR-17' => 'Splitsko-dalmatinska županija', + 'HR-18' => 'Istarska županija', + 'HR-19' => 'Dubrovačko-neretvanska županija', + 'HR-20' => 'Međimurska županija', + 'HR-21' => 'Grad Zagreb', ]; } @@ -88,42 +88,42 @@ private function getDataForCroatia() private function getDataForIndia() { return [ - ['IN', 'AN', 'Andaman and Nicobar Islands'], - ['IN', 'AP', 'Andhra Pradesh'], - ['IN', 'AR', 'Arunachal Pradesh'], - ['IN', 'AS', 'Assam'], - ['IN', 'BR', 'Bihar'], - ['IN', 'CH', 'Chandigarh'], - ['IN', 'CT', 'Chhattisgarh'], - ['IN', 'DN', 'Dadra and Nagar Haveli'], - ['IN', 'DD', 'Daman and Diu'], - ['IN', 'DL', 'Delhi'], - ['IN', 'GA', 'Goa'], - ['IN', 'GJ', 'Gujarat'], - ['IN', 'HR', 'Haryana'], - ['IN', 'HP', 'Himachal Pradesh'], - ['IN', 'JK', 'Jammu and Kashmir'], - ['IN', 'JH', 'Jharkhand'], - ['IN', 'KA', 'Karnataka'], - ['IN', 'KL', 'Kerala'], - ['IN', 'LD', 'Lakshadweep'], - ['IN', 'MP', 'Madhya Pradesh'], - ['IN', 'MH', 'Maharashtra'], - ['IN', 'MN', 'Manipur'], - ['IN', 'ML', 'Meghalaya'], - ['IN', 'MZ', 'Mizoram'], - ['IN', 'NL', 'Nagaland'], - ['IN', 'OR', 'Odisha'], - ['IN', 'PY', 'Puducherry'], - ['IN', 'PB', 'Punjab'], - ['IN', 'RJ', 'Rajasthan'], - ['IN', 'SK', 'Sikkim'], - ['IN', 'TN', 'Tamil Nadu'], - ['IN', 'TG', 'Telangana'], - ['IN', 'TR', 'Tripura'], - ['IN', 'UP', 'Uttar Pradesh'], - ['IN', 'UT', 'Uttarakhand'], - ['IN', 'WB', 'West Bengal'] + 'AN' => 'Andaman and Nicobar Islands', + 'AP' => 'Andhra Pradesh', + 'AR' => 'Arunachal Pradesh', + 'AS' => 'Assam', + 'BR' => 'Bihar', + 'CH' => 'Chandigarh', + 'CT' => 'Chhattisgarh', + 'DN' => 'Dadra and Nagar Haveli', + 'DD' => 'Daman and Diu', + 'DL' => 'Delhi', + 'GA' => 'Goa', + 'GJ' => 'Gujarat', + 'HR' => 'Haryana', + 'HP' => 'Himachal Pradesh', + 'JK' => 'Jammu and Kashmir', + 'JH' => 'Jharkhand', + 'KA' => 'Karnataka', + 'KL' => 'Kerala', + 'LD' => 'Lakshadweep', + 'MP' => 'Madhya Pradesh', + 'MH' => 'Maharashtra', + 'MN' => 'Manipur', + 'ML' => 'Meghalaya', + 'MZ' => 'Mizoram', + 'NL' => 'Nagaland', + 'OR' => 'Odisha', + 'PY' => 'Puducherry', + 'PB' => 'Punjab', + 'RJ' => 'Rajasthan', + 'SK' => 'Sikkim', + 'TN' => 'Tamil Nadu', + 'TG' => 'Telangana', + 'TR' => 'Tripura', + 'UP' => 'Uttar Pradesh', + 'UT' => 'Uttarakhand', + 'WB' => 'West Bengal', ]; } @@ -131,36 +131,22 @@ private function getDataForIndia() * Add country regions data to appropriate tables. * * @param ModuleDataSetupInterface $setup + * @param string $countryId * @param array $data * @return void */ - private function addCountryRegions(ModuleDataSetupInterface $setup, array $data) + private function addCountryRegions(ModuleDataSetupInterface $setup, string $countryId, array $data) { /** * Fill table directory/country_region * Fill table directory/country_region_name for en_US locale */ - foreach ($data as $row) { - $bind = ['country_id' => $row[0], 'code' => $row[1], 'default_name' => $row[2]]; + foreach ($data as $code => $name) { + $bind = ['country_id' => $countryId, 'code' => $code, 'default_name' => $name]; $setup->getConnection()->insert($setup->getTable('directory_country_region'), $bind); $regionId = $setup->getConnection()->lastInsertId($setup->getTable('directory_country_region')); - $bind = ['locale' => 'en_US', 'region_id' => $regionId, 'name' => $row[2]]; + $bind = ['locale' => 'en_US', 'region_id' => $regionId, 'name' => $name]; $setup->getConnection()->insert($setup->getTable('directory_country_region_name'), $bind); } - /** - * Upgrade core_config_data general/region/state_required field. - */ - $countries = $this->directoryData->getCountryCollection()->getCountriesWithRequiredStates(); - $setup->getConnection()->update( - $setup->getTable('core_config_data'), - [ - 'value' => implode(',', array_keys($countries)) - ], - [ - 'scope="default"', - 'scope_id=0', - 'path=?' => Data::XML_PATH_STATES_REQUIRED - ] - ); } } diff --git a/app/code/Magento/Directory/etc/di.xml b/app/code/Magento/Directory/etc/di.xml index 3bc50e3bc0316..b1b94d6d1edb5 100644 --- a/app/code/Magento/Directory/etc/di.xml +++ b/app/code/Magento/Directory/etc/di.xml @@ -34,10 +34,6 @@ DirectoryHelperDataProxy - - FR - DE - From 80001a1692f43acd5fe648e06896e2323c8b6a4f Mon Sep 17 00:00:00 2001 From: alojua Date: Thu, 6 Sep 2018 16:03:43 +0200 Subject: [PATCH 2/3] [Fix] Set country codes in right places --- app/code/Magento/Directory/Setup/UpgradeData.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Directory/Setup/UpgradeData.php b/app/code/Magento/Directory/Setup/UpgradeData.php index f4e9c1206525d..9a276d7cc7b80 100644 --- a/app/code/Magento/Directory/Setup/UpgradeData.php +++ b/app/code/Magento/Directory/Setup/UpgradeData.php @@ -41,10 +41,10 @@ public function __construct(Data $directoryData) public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { if (version_compare($context->getVersion(), '2.0.1', '<')) { - $this->addCountryRegions($setup, 'IN', $this->getDataForCroatia()); + $this->addCountryRegions($setup, 'HR', $this->getDataForCroatia()); } if (version_compare($context->getVersion(), '2.0.2', '<')) { - $this->addCountryRegions($setup, 'HR', $this->getDataForIndia()); + $this->addCountryRegions($setup, 'IN', $this->getDataForIndia()); } } From 875c3948257032c34cdc2c910ebbebb41a754c6b Mon Sep 17 00:00:00 2001 From: alojua Date: Thu, 6 Sep 2018 16:11:50 +0200 Subject: [PATCH 3/3] [Fix] Add required countries only for IN and HR while keeping previous functionality --- .../Model/ResourceModel/Country/Collection.php | 2 -- app/code/Magento/Directory/Setup/InstallData.php | 11 +++++++++++ app/code/Magento/Directory/Setup/UpgradeData.php | 15 +++++++++++++++ app/code/Magento/Directory/etc/di.xml | 4 ++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php b/app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php index 93a6149e10fcf..da5ad64f8b239 100644 --- a/app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php +++ b/app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php @@ -64,8 +64,6 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab private $allowedCountriesReader; /** - * @deprecated - * * @var string[] * @since 100.1.0 */ diff --git a/app/code/Magento/Directory/Setup/InstallData.php b/app/code/Magento/Directory/Setup/InstallData.php index 12c3fba214804..33c3ae4558e16 100644 --- a/app/code/Magento/Directory/Setup/InstallData.php +++ b/app/code/Magento/Directory/Setup/InstallData.php @@ -842,5 +842,16 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface 'value' => 1 ] ); + + $countries = $this->directoryData->getCountryCollection()->getCountriesWithRequiredStates(); + $setup->getConnection()->insert( + $setup->getTable('core_config_data'), + [ + 'scope' => 'default', + 'scope_id' => 0, + 'path' => Data::XML_PATH_STATES_REQUIRED, + 'value' => implode(',', array_keys($countries)) + ] + ); } } diff --git a/app/code/Magento/Directory/Setup/UpgradeData.php b/app/code/Magento/Directory/Setup/UpgradeData.php index 9a276d7cc7b80..d149a83ce8e9d 100644 --- a/app/code/Magento/Directory/Setup/UpgradeData.php +++ b/app/code/Magento/Directory/Setup/UpgradeData.php @@ -148,5 +148,20 @@ private function addCountryRegions(ModuleDataSetupInterface $setup, string $coun $bind = ['locale' => 'en_US', 'region_id' => $regionId, 'name' => $name]; $setup->getConnection()->insert($setup->getTable('directory_country_region_name'), $bind); } + + /** + * Upgrade core_config_data general/region/state_required field. + */ + $setup->getConnection()->update( + $setup->getTable('core_config_data'), + [ + 'value' => new \Zend_Db_Expr("CONCAT(value, '," . $countryId . "')") + ], + [ + 'scope="default"', + 'scope_id=0', + 'path=?' => Data::XML_PATH_STATES_REQUIRED + ] + ); } } diff --git a/app/code/Magento/Directory/etc/di.xml b/app/code/Magento/Directory/etc/di.xml index b1b94d6d1edb5..3bc50e3bc0316 100644 --- a/app/code/Magento/Directory/etc/di.xml +++ b/app/code/Magento/Directory/etc/di.xml @@ -34,6 +34,10 @@ DirectoryHelperDataProxy + + FR + DE +