Skip to content

Commit ac1eb6d

Browse files
committed
#12378: Regions list in Directory module for India
1 parent a50843f commit ac1eb6d

File tree

2 files changed

+71
-11
lines changed

2 files changed

+71
-11
lines changed

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

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,21 @@ 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->addCroatia($setup);
44+
$this->addCountryRegions($setup, $this->getDataForCroatia());
45+
}
46+
if (version_compare($context->getVersion(), '2.0.2', '<')) {
47+
$this->addCountryRegions($setup, $this->getDataForIndia());
4548
}
4649
}
4750

4851
/**
49-
* Add Croatia and it's states to appropriate tables.
52+
* Croatian states data.
5053
*
51-
* @param ModuleDataSetupInterface $setup
52-
* @return void
54+
* @return array
5355
*/
54-
private function addCroatia($setup)
56+
private function getDataForCroatia()
5557
{
56-
/**
57-
* Fill table directory/country_region
58-
* Fill table directory/country_region_name for en_US locale
59-
*/
60-
$data = [
58+
return [
6159
['HR', 'HR-01', 'Zagrebačka županija'],
6260
['HR', 'HR-02', 'Krapinsko-zagorska županija'],
6361
['HR', 'HR-03', 'Sisačko-moslavačka županija'],
@@ -80,6 +78,68 @@ private function addCroatia($setup)
8078
['HR', 'HR-20', 'Međimurska županija'],
8179
['HR', 'HR-21', 'Grad Zagreb']
8280
];
81+
}
82+
83+
/**
84+
* Indian states data.
85+
*
86+
* @return array
87+
*/
88+
private function getDataForIndia()
89+
{
90+
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']
127+
];
128+
}
129+
130+
/**
131+
* Add country regions data to appropriate tables.
132+
*
133+
* @param ModuleDataSetupInterface $setup
134+
* @param array $data
135+
* @return void
136+
*/
137+
private function addCountryRegions(ModuleDataSetupInterface $setup, array $data)
138+
{
139+
/**
140+
* Fill table directory/country_region
141+
* Fill table directory/country_region_name for en_US locale
142+
*/
83143
foreach ($data as $row) {
84144
$bind = ['country_id' => $row[0], 'code' => $row[1], 'default_name' => $row[2]];
85145
$setup->getConnection()->insert($setup->getTable('directory_country_region'), $bind);

app/code/Magento/Directory/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_Directory" setup_version="2.0.1">
9+
<module name="Magento_Directory" setup_version="2.0.2">
1010
<sequence>
1111
<module name="Magento_Store"/>
1212
</sequence>

0 commit comments

Comments
 (0)