Skip to content

Commit 51f553c

Browse files
ENGCOM-2988: [Fix] Do not modify current list of countries with require states during setup upgrade #16885
- Merge Pull Request #16885 from jalogut/magento2:fix-states-required - Merged commits: 1. 80384fc 2. 80001a1 3. 875c394
2 parents 0ba4eda + 875c394 commit 51f553c

File tree

2 files changed

+69
-66
lines changed

2 files changed

+69
-66
lines changed

app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ public function setForegroundCountries($foregroundCountries)
349349
}
350350

351351
/**
352+
* @deprecated use \Magento\Directory\Helper\Data::getCountriesWithStatesRequired() instead
353+
*
352354
* Get list of countries with required states
353355
*
354356
* @return \Magento\Directory\Model\Country[]

app/code/Magento/Directory/Setup/UpgradeData.php

Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(Data $directoryData)
3232
}
3333

3434
/**
35-
* Upgrades data for Directry module.
35+
* Upgrades data for Directory module.
3636
*
3737
* @param ModuleDataSetupInterface $setup
3838
* @param ModuleContextInterface $context
@@ -41,10 +41,10 @@ public function __construct(Data $directoryData)
4141
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
4242
{
4343
if (version_compare($context->getVersion(), '2.0.1', '<')) {
44-
$this->addCountryRegions($setup, $this->getDataForCroatia());
44+
$this->addCountryRegions($setup, 'HR', $this->getDataForCroatia());
4545
}
4646
if (version_compare($context->getVersion(), '2.0.2', '<')) {
47-
$this->addCountryRegions($setup, $this->getDataForIndia());
47+
$this->addCountryRegions($setup, 'IN', $this->getDataForIndia());
4848
}
4949
}
5050

@@ -56,27 +56,27 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
5656
private function getDataForCroatia()
5757
{
5858
return [
59-
['HR', 'HR-01', 'Zagrebačka županija'],
60-
['HR', 'HR-02', 'Krapinsko-zagorska županija'],
61-
['HR', 'HR-03', 'Sisačko-moslavačka županija'],
62-
['HR', 'HR-04', 'Karlovačka županija'],
63-
['HR', 'HR-05', 'Varaždinska županija'],
64-
['HR', 'HR-06', 'Koprivničko-križevačka županija'],
65-
['HR', 'HR-07', 'Bjelovarsko-bilogorska županija'],
66-
['HR', 'HR-08', 'Primorsko-goranska županija'],
67-
['HR', 'HR-09', 'Ličko-senjska županija'],
68-
['HR', 'HR-10', 'Virovitičko-podravska županija'],
69-
['HR', 'HR-11', 'Požeško-slavonska županija'],
70-
['HR', 'HR-12', 'Brodsko-posavska županija'],
71-
['HR', 'HR-13', 'Zadarska županija'],
72-
['HR', 'HR-14', 'Osječko-baranjska županija'],
73-
['HR', 'HR-15', 'Šibensko-kninska županija'],
74-
['HR', 'HR-16', 'Vukovarsko-srijemska županija'],
75-
['HR', 'HR-17', 'Splitsko-dalmatinska županija'],
76-
['HR', 'HR-18', 'Istarska županija'],
77-
['HR', 'HR-19', 'Dubrovačko-neretvanska županija'],
78-
['HR', 'HR-20', 'Međimurska županija'],
79-
['HR', 'HR-21', 'Grad Zagreb']
59+
'HR-01' => 'Zagrebačka županija',
60+
'HR-02' => 'Krapinsko-zagorska županija',
61+
'HR-03' => 'Sisačko-moslavačka županija',
62+
'HR-04' => 'Karlovačka županija',
63+
'HR-05' => 'Varaždinska županija',
64+
'HR-06' => 'Koprivničko-križevačka županija',
65+
'HR-07' => 'Bjelovarsko-bilogorska županija',
66+
'HR-08' => 'Primorsko-goranska županija',
67+
'HR-09' => 'Ličko-senjska županija',
68+
'HR-10' => 'Virovitičko-podravska županija',
69+
'HR-11' => 'Požeško-slavonska županija',
70+
'HR-12' => 'Brodsko-posavska županija',
71+
'HR-13' => 'Zadarska županija',
72+
'HR-14' => 'Osječko-baranjska županija',
73+
'HR-15' => 'Šibensko-kninska županija',
74+
'HR-16' => 'Vukovarsko-srijemska županija',
75+
'HR-17' => 'Splitsko-dalmatinska županija',
76+
'HR-18' => 'Istarska županija',
77+
'HR-19' => 'Dubrovačko-neretvanska županija',
78+
'HR-20' => 'Međimurska županija',
79+
'HR-21' => 'Grad Zagreb',
8080
];
8181
}
8282

@@ -88,73 +88,74 @@ private function getDataForCroatia()
8888
private function getDataForIndia()
8989
{
9090
return [
91-
['IN', 'AN', 'Andaman and Nicobar Islands'],
92-
['IN', 'AP', 'Andhra Pradesh'],
93-
['IN', 'AR', 'Arunachal Pradesh'],
94-
['IN', 'AS', 'Assam'],
95-
['IN', 'BR', 'Bihar'],
96-
['IN', 'CH', 'Chandigarh'],
97-
['IN', 'CT', 'Chhattisgarh'],
98-
['IN', 'DN', 'Dadra and Nagar Haveli'],
99-
['IN', 'DD', 'Daman and Diu'],
100-
['IN', 'DL', 'Delhi'],
101-
['IN', 'GA', 'Goa'],
102-
['IN', 'GJ', 'Gujarat'],
103-
['IN', 'HR', 'Haryana'],
104-
['IN', 'HP', 'Himachal Pradesh'],
105-
['IN', 'JK', 'Jammu and Kashmir'],
106-
['IN', 'JH', 'Jharkhand'],
107-
['IN', 'KA', 'Karnataka'],
108-
['IN', 'KL', 'Kerala'],
109-
['IN', 'LD', 'Lakshadweep'],
110-
['IN', 'MP', 'Madhya Pradesh'],
111-
['IN', 'MH', 'Maharashtra'],
112-
['IN', 'MN', 'Manipur'],
113-
['IN', 'ML', 'Meghalaya'],
114-
['IN', 'MZ', 'Mizoram'],
115-
['IN', 'NL', 'Nagaland'],
116-
['IN', 'OR', 'Odisha'],
117-
['IN', 'PY', 'Puducherry'],
118-
['IN', 'PB', 'Punjab'],
119-
['IN', 'RJ', 'Rajasthan'],
120-
['IN', 'SK', 'Sikkim'],
121-
['IN', 'TN', 'Tamil Nadu'],
122-
['IN', 'TG', 'Telangana'],
123-
['IN', 'TR', 'Tripura'],
124-
['IN', 'UP', 'Uttar Pradesh'],
125-
['IN', 'UT', 'Uttarakhand'],
126-
['IN', 'WB', 'West Bengal']
91+
'AN' => 'Andaman and Nicobar Islands',
92+
'AP' => 'Andhra Pradesh',
93+
'AR' => 'Arunachal Pradesh',
94+
'AS' => 'Assam',
95+
'BR' => 'Bihar',
96+
'CH' => 'Chandigarh',
97+
'CT' => 'Chhattisgarh',
98+
'DN' => 'Dadra and Nagar Haveli',
99+
'DD' => 'Daman and Diu',
100+
'DL' => 'Delhi',
101+
'GA' => 'Goa',
102+
'GJ' => 'Gujarat',
103+
'HR' => 'Haryana',
104+
'HP' => 'Himachal Pradesh',
105+
'JK' => 'Jammu and Kashmir',
106+
'JH' => 'Jharkhand',
107+
'KA' => 'Karnataka',
108+
'KL' => 'Kerala',
109+
'LD' => 'Lakshadweep',
110+
'MP' => 'Madhya Pradesh',
111+
'MH' => 'Maharashtra',
112+
'MN' => 'Manipur',
113+
'ML' => 'Meghalaya',
114+
'MZ' => 'Mizoram',
115+
'NL' => 'Nagaland',
116+
'OR' => 'Odisha',
117+
'PY' => 'Puducherry',
118+
'PB' => 'Punjab',
119+
'RJ' => 'Rajasthan',
120+
'SK' => 'Sikkim',
121+
'TN' => 'Tamil Nadu',
122+
'TG' => 'Telangana',
123+
'TR' => 'Tripura',
124+
'UP' => 'Uttar Pradesh',
125+
'UT' => 'Uttarakhand',
126+
'WB' => 'West Bengal',
127127
];
128128
}
129129

130130
/**
131131
* Add country regions data to appropriate tables.
132132
*
133133
* @param ModuleDataSetupInterface $setup
134+
* @param string $countryId
134135
* @param array $data
135136
* @return void
136137
*/
137-
private function addCountryRegions(ModuleDataSetupInterface $setup, array $data)
138+
private function addCountryRegions(ModuleDataSetupInterface $setup, string $countryId, array $data)
138139
{
139140
/**
140141
* Fill table directory/country_region
141142
* Fill table directory/country_region_name for en_US locale
142143
*/
143-
foreach ($data as $row) {
144-
$bind = ['country_id' => $row[0], 'code' => $row[1], 'default_name' => $row[2]];
144+
foreach ($data as $code => $name) {
145+
$bind = ['country_id' => $countryId, 'code' => $code, 'default_name' => $name];
145146
$setup->getConnection()->insert($setup->getTable('directory_country_region'), $bind);
146147
$regionId = $setup->getConnection()->lastInsertId($setup->getTable('directory_country_region'));
147-
$bind = ['locale' => 'en_US', 'region_id' => $regionId, 'name' => $row[2]];
148+
$bind = ['locale' => 'en_US', 'region_id' => $regionId, 'name' => $name];
148149
$setup->getConnection()->insert($setup->getTable('directory_country_region_name'), $bind);
149150
}
151+
150152
/**
151153
* Upgrade core_config_data general/region/state_required field.
152154
*/
153-
$countries = $this->directoryData->getCountryCollection()->getCountriesWithRequiredStates();
154155
$setup->getConnection()->update(
155156
$setup->getTable('core_config_data'),
156157
[
157-
'value' => implode(',', array_keys($countries))
158+
'value' => new \Zend_Db_Expr("CONCAT(value, '," . $countryId . "')")
158159
],
159160
[
160161
'scope="default"',

0 commit comments

Comments
 (0)