Skip to content

Commit 875c394

Browse files
committed
[Fix] Add required countries only for IN and HR while keeping previous functionality
1 parent 80001a1 commit 875c394

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
6464
private $allowedCountriesReader;
6565

6666
/**
67-
* @deprecated
68-
*
6967
* @var string[]
7068
* @since 100.1.0
7169
*/

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,5 +842,16 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
842842
'value' => 1
843843
]
844844
);
845+
846+
$countries = $this->directoryData->getCountryCollection()->getCountriesWithRequiredStates();
847+
$setup->getConnection()->insert(
848+
$setup->getTable('core_config_data'),
849+
[
850+
'scope' => 'default',
851+
'scope_id' => 0,
852+
'path' => Data::XML_PATH_STATES_REQUIRED,
853+
'value' => implode(',', array_keys($countries))
854+
]
855+
);
845856
}
846857
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,20 @@ private function addCountryRegions(ModuleDataSetupInterface $setup, string $coun
148148
$bind = ['locale' => 'en_US', 'region_id' => $regionId, 'name' => $name];
149149
$setup->getConnection()->insert($setup->getTable('directory_country_region_name'), $bind);
150150
}
151+
152+
/**
153+
* Upgrade core_config_data general/region/state_required field.
154+
*/
155+
$setup->getConnection()->update(
156+
$setup->getTable('core_config_data'),
157+
[
158+
'value' => new \Zend_Db_Expr("CONCAT(value, '," . $countryId . "')")
159+
],
160+
[
161+
'scope="default"',
162+
'scope_id=0',
163+
'path=?' => Data::XML_PATH_STATES_REQUIRED
164+
]
165+
);
151166
}
152167
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
<type name="Magento\Directory\Model\ResourceModel\Country\Collection" shared="false">
3535
<arguments>
3636
<argument name="helperData" xsi:type="object">DirectoryHelperDataProxy</argument>
37+
<argument name="countriesWithNotRequiredStates" xsi:type="array">
38+
<item name="FR" xsi:type="string">FR</item>
39+
<item name="DE" xsi:type="string">DE</item>
40+
</argument>
3741
</arguments>
3842
</type>
3943
<preference for="Magento\Directory\Model\Country\Postcode\ConfigInterface" type="Magento\Directory\Model\Country\Postcode\Config" />

0 commit comments

Comments
 (0)