Skip to content

Commit c3dd51d

Browse files
author
Sergey Kovalenko
committed
MAGETWO-56941: CLONE - CLONE - [Github] Allowed countries for customer address in admin using storeview configuration #2946
1 parent 1898aaf commit c3dd51d

File tree

8 files changed

+68
-29
lines changed

8 files changed

+68
-29
lines changed

app/code/Magento/Customer/Model/CountryHandler.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,19 @@
77
namespace Magento\Customer\Model;
88

99
use Magento\Customer\Model\Config\Share;
10+
use Magento\Directory\Model\CountryHandlerInterface;
1011
use Magento\Framework\App\Config\ScopeConfigInterface;
1112
use Magento\Framework\Data\Collection\AbstractDb;
1213
use Magento\Store\Api\Data\WebsiteInterface;
1314
use Magento\Store\Model\ScopeInterface;
14-
use Magento\Store\Model\Store;
1515
use Magento\Store\Model\StoreManagerInterface;
16-
use Magento\Store\Model\Website;
1716

1817
/**
1918
* Class CountryHandler.
2019
* @package Magento\Customer\Model
2120
*/
22-
class CountryHandler
21+
class CountryHandler implements CountryHandlerInterface
2322
{
24-
const ALLOWED_COUNTRIES_PATH = 'general/country/allow';
25-
2623
/**
2724
* @var ScopeConfigInterface
2825
*/

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77
namespace Magento\Customer\Setup;
88

99
use Magento\Customer\Model\Customer;
10-
use Magento\Customer\Model\CountryHandler;
11-
use Magento\Framework\App\Config\ScopeConfigInterface;
10+
use Magento\Directory\Model\CountryHandlerInterface;
1211
use Magento\Framework\Encryption\Encryptor;
1312
use Magento\Framework\Indexer\IndexerRegistry;
14-
use Magento\Framework\ObjectManager\ObjectManager;
1513
use Magento\Framework\Setup\SetupInterface;
1614
use Magento\Framework\Setup\UpgradeDataInterface;
1715
use Magento\Framework\Setup\ModuleContextInterface;
1816
use Magento\Framework\Setup\ModuleDataSetupInterface;
19-
use Magento\Store\Api\Data\WebsiteInterface;
2017
use Magento\Store\Model\ScopeInterface;
2118
use Magento\Store\Model\StoreManagerInterface;
2219

@@ -142,11 +139,11 @@ private function getStoreManager()
142139

143140
/**
144141
* @deprecated
145-
* @return CountryHandler
142+
* @return CountryHandlerInterface
146143
*/
147144
private function getCountryHandler()
148145
{
149-
return \Magento\Framework\App\ObjectManager::getInstance()->get(CountryHandler::class);
146+
return \Magento\Framework\App\ObjectManager::getInstance()->get(CountryHandlerInterface::class);
150147
}
151148

152149
/**
@@ -197,7 +194,7 @@ private function migrateStoresAllowedCountriesToWebsite(SetupInterface $setup)
197194
$connection->delete(
198195
$setup->getTable('core_config_data'),
199196
[
200-
'path = ?' => CountryHandler::ALLOWED_COUNTRIES_PATH,
197+
'path = ?' => CountryHandlerInterface::ALLOWED_COUNTRIES_PATH,
201198
'scope = ?' => ScopeInterface::SCOPE_STORES
202199
]
203200
);
@@ -210,7 +207,7 @@ private function migrateStoresAllowedCountriesToWebsite(SetupInterface $setup)
210207
'value' => implode(',', $countries)
211208
],
212209
[
213-
'path = ?' => CountryHandler::ALLOWED_COUNTRIES_PATH,
210+
'path = ?' => CountryHandlerInterface::ALLOWED_COUNTRIES_PATH,
214211
'scope_id = ?' => $scopeId,
215212
'scope = ?' => ScopeInterface::SCOPE_WEBSITES
216213
]

app/code/Magento/Customer/Test/Unit/Model/CountryHandlerTest.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88

99
use Magento\Customer\Model\Config\Share;
1010
use Magento\Customer\Model\CountryHandler;
11+
use Magento\Directory\Model\CountryHandlerInterface;
1112
use Magento\Framework\App\Config\ScopeConfigInterface;
1213
use Magento\Framework\Data\Collection\AbstractDb;
1314
use Magento\Store\Api\Data\WebsiteInterface;
1415
use Magento\Store\Model\ScopeInterface;
1516
use Magento\Store\Model\StoreManagerInterface;
1617

17-
class CountryHandlerTest extends \PHPUnit_Framework_TestCase
18+
class CountryHandlerInterfaceTest extends \PHPUnit_Framework_TestCase
1819
{
1920
/**
2021
* @var \PHPUnit_Framework_MockObject_MockObject | ScopeConfigInterface
@@ -32,7 +33,7 @@ class CountryHandlerTest extends \PHPUnit_Framework_TestCase
3233
private $configShareMock;
3334

3435
/**
35-
* @var CountryHandler
36+
* @var CountryHandlerInterface
3637
*/
3738
private $countryHandler;
3839

@@ -75,12 +76,12 @@ public function testGetAllowedCountriesInGlobalScope()
7576
$this->scopeConfigMock->expects($this->exactly(2))
7677
->method('getValue')
7778
->withConsecutive(
78-
[CountryHandler::ALLOWED_COUNTRIES_PATH, 'website', 1],
79-
[CountryHandler::ALLOWED_COUNTRIES_PATH, 'website', 2]
79+
[CountryHandlerInterface::ALLOWED_COUNTRIES_PATH, 'website', 1],
80+
[CountryHandlerInterface::ALLOWED_COUNTRIES_PATH, 'website', 2]
8081
)
8182
->willReturnMap([
82-
[CountryHandler::ALLOWED_COUNTRIES_PATH, 'website', 1, 'AZ,AM'],
83-
[CountryHandler::ALLOWED_COUNTRIES_PATH, 'website', 2, 'AF,AM']
83+
[CountryHandlerInterface::ALLOWED_COUNTRIES_PATH, 'website', 1, 'AZ,AM'],
84+
[CountryHandlerInterface::ALLOWED_COUNTRIES_PATH, 'website', 2, 'AF,AM']
8485
]);
8586

8687
$expected = [
@@ -103,7 +104,7 @@ public function testGetAllowedCountriesWithEmptyFilter()
103104
->willReturn($website1);
104105
$this->scopeConfigMock->expects($this->once())
105106
->method('getValue')
106-
->with(CountryHandler::ALLOWED_COUNTRIES_PATH, 'website', 1)
107+
->with(CountryHandlerInterface::ALLOWED_COUNTRIES_PATH, 'website', 1)
107108
->willReturn('AM');
108109

109110
$this->assertEquals(['AM' => 'AM'], $this->countryHandler->getAllowedCountries());
@@ -113,7 +114,7 @@ public function testGetAllowedCountriesWithoutGlobalScope()
113114
{
114115
$this->scopeConfigMock->expects($this->once())
115116
->method('getValue')
116-
->with(CountryHandler::ALLOWED_COUNTRIES_PATH, 'website', 1)
117+
->with(CountryHandlerInterface::ALLOWED_COUNTRIES_PATH, 'website', 1)
117118
->willReturn('AM');
118119

119120
$this->configShareMock->expects($this->atLeastOnce())
@@ -129,7 +130,7 @@ public function testLoadByScope()
129130
{
130131
$this->scopeConfigMock->expects($this->once())
131132
->method('getValue')
132-
->with(CountryHandler::ALLOWED_COUNTRIES_PATH, 'website', 1)
133+
->with(CountryHandlerInterface::ALLOWED_COUNTRIES_PATH, 'website', 1)
133134
->willReturn('AM');
134135

135136
$collectionMock = $this->getMockBuilder(AbstractDb::class)

app/code/Magento/Customer/Test/Unit/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsitesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Magento\Customer\Test\Unit\Model\ResourceModel\Address\Attribute\Source;
88

99
use Magento\Customer\Model\ResourceModel\Address\Attribute\Source\CountryWithWebsites;
10-
use Magento\Customer\Model\CountryHandler;
10+
use Magento\Directory\Model\CountryHandlerInterface;
1111
use Magento\Framework\Data\Collection\AbstractDb;
1212
use Magento\Store\Api\Data\WebsiteInterface;
1313
use Magento\Store\Model\StoreManagerInterface;
@@ -41,7 +41,7 @@ public function setUp()
4141
->setMethods(['create'])
4242
->disableOriginalConstructor()
4343
->getMock();
44-
$this->countryHandlerMock = $this->getMockBuilder(CountryHandler::class)
44+
$this->countryHandlerMock = $this->getMockBuilder(CountryHandlerInterface::class)
4545
->disableOriginalConstructor()
4646
->getMock();
4747
$eavCollectionFactoryMock =

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
type="Magento\Customer\Helper\View" />
5252
<preference for="Magento\Customer\Model\Address\CustomAttributeListInterface"
5353
type="Magento\Customer\Model\Address\CustomAttributeList" />
54+
<preference for="\Magento\Directory\Model\CountryHandlerInterface"
55+
type="Magento\Customer\Model\CountryHandler" />
5456
<type name="Magento\Customer\Model\Session">
5557
<arguments>
5658
<argument name="configShare" xsi:type="object">Magento\Customer\Model\Config\Share\Proxy</argument>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Directory\Model;
8+
9+
use Magento\Framework\Data\Collection\AbstractDb;
10+
use Magento\Store\Model\ScopeInterface;
11+
12+
/**
13+
* Interface CountryHandlerInterface.
14+
* @package Magento\Directory\Model
15+
*/
16+
interface CountryHandlerInterface
17+
{
18+
const ALLOWED_COUNTRIES_PATH = 'general/country/allow';
19+
20+
/**
21+
* Retrieve all allowed in current scope countries.
22+
* @param null $filter
23+
* @param string $scope
24+
* @param bool $ignoreGlobalScope
25+
* @return array
26+
*/
27+
public function getAllowedCountries(
28+
$filter = null,
29+
$scope = ScopeInterface::SCOPE_WEBSITE,
30+
$ignoreGlobalScope = false
31+
);
32+
33+
/**
34+
* Filter directory collection by allowed in website countries.
35+
* @param $filter
36+
* @param string $scope
37+
* @param \Magento\Framework\Data\Collection\AbstractDb $collection
38+
* @return AbstractDb
39+
*/
40+
public function loadByScope($filter, $scope = ScopeInterface::SCOPE_STORE, AbstractDb $collection);
41+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Directory Country Resource Collection
1111
*/
1212
namespace Magento\Directory\Model\ResourceModel\Country;
13-
use Magento\Customer\Model\CountryHandler;
13+
use Magento\Directory\Model\CountryHandlerInterface;
1414
use Magento\Framework\App\ObjectManager;
1515
use Magento\Store\Model\ScopeInterface;
1616

@@ -123,11 +123,11 @@ protected function _construct()
123123

124124
/**
125125
* @deprecated
126-
* @return CountryHandler
126+
* @return \Magento\Directory\Model\CountryHandlerInterface
127127
*/
128128
private function getCountryHandler()
129129
{
130-
return ObjectManager::getInstance()->get(CountryHandler::class);
130+
return ObjectManager::getInstance()->get(CountryHandlerInterface::class);
131131
}
132132

133133
/**

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/Address.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Backend\Model\Session\Quote;
99
use Magento\Customer\Model\CountryHandler;
10+
use Magento\Directory\Model\CountryHandlerInterface;
1011
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\Data\Form\Element\AbstractElement;
1213
use Magento\Framework\Pricing\PriceCurrencyInterface;
@@ -308,11 +309,11 @@ private function getCountriesCollection()
308309

309310
/**
310311
* @deprecated
311-
* @return CountryHandler
312+
* @return CountryHandlerInterface
312313
*/
313314
private function getCountryHandler()
314315
{
315-
return ObjectManager::getInstance()->get(CountryHandler::class);
316+
return ObjectManager::getInstance()->get(CountryHandlerInterface::class);
316317
}
317318

318319
/**

0 commit comments

Comments
 (0)