Skip to content

Commit 97fdd33

Browse files
committed
Revert "#37796: Fixed issue with adding new country regions"
This reverts commit 65e0ea4.
1 parent cd9488f commit 97fdd33

File tree

2 files changed

+20
-149
lines changed

2 files changed

+20
-149
lines changed

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

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,46 @@
66

77
namespace Magento\Directory\Setup;
88

9-
use Magento\Directory\Helper\Data;
109
use Magento\Framework\App\ResourceConnection;
1110
use Magento\Framework\DB\Adapter\AdapterInterface;
1211

1312
/**
14-
* Add Required Regions for Country
13+
* Class DataInstaller
14+
* @package Magento\Directory\Setup
1515
*/
1616
class DataInstaller
1717
{
18+
/**
19+
* @var \Magento\Directory\Helper\Data
20+
*/
21+
private $data;
22+
1823
/**
1924
* @var ResourceConnection
2025
*/
2126
private $resourceConnection;
2227

2328
/**
2429
* DatInstaller constructor.
25-
*
30+
* @param \Magento\Directory\Helper\Data $data
2631
* @param ResourceConnection $resourceConnection
2732
*/
2833
public function __construct(
34+
\Magento\Directory\Helper\Data $data,
2935
ResourceConnection $resourceConnection
3036
) {
37+
$this->data = $data;
3138
$this->resourceConnection = $resourceConnection;
3239
}
3340

3441
/**
3542
* Add country-region data.
3643
*
37-
* @param AdapterInterface $adapter
38-
* @param array $data
39-
* @return void
44+
* @param AdapterInterface $adapter
45+
* @param array $data
4046
*/
41-
public function addCountryRegions(AdapterInterface $adapter, array $data): void
47+
public function addCountryRegions(AdapterInterface $adapter, array $data)
4248
{
43-
$where = [
44-
$adapter->quoteInto('path = ?', Data::XML_PATH_STATES_REQUIRED),
45-
$adapter->quoteInto('scope = ?', 'default'),
46-
$adapter->quoteInto('scope_id = ?', 0),
47-
];
48-
49-
$select = $adapter->select()
50-
->from($this->resourceConnection->getTableName('core_config_data'), 'value')
51-
->where(implode(' AND ', $where));
52-
53-
$currRequiredStates = $adapter->fetchOne($select);
54-
$currRequiredStates = (!empty($currRequiredStates)) ? explode(',', $currRequiredStates) : [];
55-
5649
/**
5750
* Fill table directory/country_region
5851
* Fill table directory/country_region_name for en_US locale
@@ -63,21 +56,21 @@ public function addCountryRegions(AdapterInterface $adapter, array $data): void
6356
$regionId = $adapter->lastInsertId($this->resourceConnection->getTableName('directory_country_region'));
6457
$bind = ['locale' => 'en_US', 'region_id' => $regionId, 'name' => $row[2]];
6558
$adapter->insert($this->resourceConnection->getTableName('directory_country_region_name'), $bind);
66-
67-
if (!in_array($row[0], $currRequiredStates)) {
68-
$currRequiredStates[] = $row[0];
69-
}
7059
}
71-
7260
/**
7361
* Upgrade core_config_data general/region/state_required field.
7462
*/
63+
$countries = $this->data->getCountryCollection()->getCountriesWithRequiredStates();
7564
$adapter->update(
7665
$this->resourceConnection->getTableName('core_config_data'),
7766
[
78-
'value' => implode(',', $currRequiredStates)
67+
'value' => implode(',', array_keys($countries))
7968
],
80-
$where
69+
[
70+
'scope="default"',
71+
'scope_id=0',
72+
'path=?' => \Magento\Directory\Helper\Data::XML_PATH_STATES_REQUIRED
73+
]
8174
);
8275
}
8376
}

dev/tests/integration/testsuite/Magento/Directory/Setup/DataInstallerTest.php

Lines changed: 0 additions & 122 deletions
This file was deleted.

0 commit comments

Comments
 (0)