Skip to content

Commit fe86a0a

Browse files
author
Sergii Kovalenko
committed
MAGETWO-56941: [Github] Allowed countries for customer address in admin using storeview configuration #2946
1 parent 4c75346 commit fe86a0a

File tree

7 files changed

+11
-31
lines changed

7 files changed

+11
-31
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ protected function getAttributesMeta(Type $entityType)
321321

322322
if ($attribute->usesSource()) {
323323
if ($code == AddressInterface::COUNTRY_ID) {
324-
$meta[$code]['arguments']['data']['config']['options'] = $this->getcountryWithWebsiteSource()
324+
$meta[$code]['arguments']['data']['config']['options'] = $this->getCountryWithWebsiteSource()
325325
->getAllOptions();
326326
} else {
327327
$meta[$code]['arguments']['data']['config']['options'] = $attribute->getSource()->getAllOptions();

app/code/Magento/Customer/Model/Plugin/AllowedCountries.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public function __construct(
4747
*/
4848
public function beforeGetAllowedCountries(
4949
\Magento\Directory\Model\AllowedCountries $subject,
50-
$scopeCode = null,
51-
$scope = ScopeInterface::SCOPE_WEBSITE
50+
$scope = ScopeInterface::SCOPE_WEBSITE,
51+
$scopeCode = null
5252
) {
5353
if ($this->shareConfig->isGlobalScope()) {
5454
//Check if we have shared accounts - than merge all website allowed countries
@@ -58,6 +58,6 @@ public function beforeGetAllowedCountries(
5858
$scope = ScopeInterface::SCOPE_WEBSITES;
5959
}
6060

61-
return [$scopeCode, $scope];
61+
return [$scope, $scopeCode];
6262
}
6363
}

app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function getAllOptions()
7878
if (!$this->shareConfig->isGlobalScope()) {
7979
foreach ($this->storeManager->getWebsites() as $website) {
8080
$countries = $this->allowedCountriesReader
81-
->getAllowedCountries($website->getId(), ScopeInterface::SCOPE_WEBSITE);
81+
->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE, $website->getId());
8282
$allowedCountries = array_merge($allowedCountries, $countries);
8383

8484
foreach ($countries as $countryCode) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ private function migrateStoresAllowedCountriesToWebsite(SetupInterface $setup)
203203
$allowedCountries = $this->mergeAllowedCountries(
204204
$allowedCountries,
205205
$this->getAllowedCountriesReader()
206-
->getAllowedCountries($store->getId(), ScopeInterface::SCOPE_STORE),
206+
->getAllowedCountries(ScopeInterface::SCOPE_STORE, $store->getId()),
207207
$store->getWebsiteId()
208208
);
209209
}
@@ -212,7 +212,7 @@ private function migrateStoresAllowedCountriesToWebsite(SetupInterface $setup)
212212
$allowedCountries = $this->mergeAllowedCountries(
213213
$allowedCountries,
214214
$this->getAllowedCountriesReader()
215-
->getAllowedCountries($website->getId(), ScopeInterface::SCOPE_WEBSITE),
215+
->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE, $website->getId()),
216216
$website->getId()
217217
);
218218
}

app/code/Magento/Directory/Model/AllowedCountries.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public function __construct(
4949
* @return array
5050
*/
5151
public function getAllowedCountries(
52-
$scopeCode = null,
53-
$scope = ScopeInterface::SCOPE_WEBSITE
52+
$scope = ScopeInterface::SCOPE_WEBSITE,
53+
$scopeCode = null
5454
) {
5555
if (empty($scopeCode)) {
5656
$scopeCode = $this->getDefaultScopeCode($scope);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private function getAllowedCountriesReader()
150150
public function loadByStore($store = null)
151151
{
152152
$allowedCountries = $this->getAllowedCountriesReader()
153-
->getAllowedCountries($store, ScopeInterface::SCOPE_STORE);
153+
->getAllowedCountries(ScopeInterface::SCOPE_STORE, $store);
154154

155155
if (!empty($allowedCountries)) {
156156
$this->addFieldToFilter("country_id", ['in' => $allowedCountries]);

app/code/Magento/Directory/Test/Unit/Model/AllowedCountriesTest.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,7 @@ public function testGetAllowedCountries()
6767

6868
$this->assertEquals(
6969
['AM' => 'AM'],
70-
$this->allowedCountriesReader->getAllowedCountries(1, ScopeInterface::SCOPE_WEBSITE, true)
70+
$this->allowedCountriesReader->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE, true)
7171
);
7272
}
73-
74-
// public function testLoadByScope()
75-
// {
76-
// $this->scopeConfigMock->expects($this->once())
77-
// ->method('getValue')
78-
// ->with(CountryHandlerInterface::ALLOWED_COUNTRIES_PATH, 'website', 1)
79-
// ->willReturn('AM');
80-
//
81-
// $collectionMock = $this->getMockBuilder(AbstractDb::class)
82-
// ->disableOriginalConstructor()
83-
// ->getMock();
84-
// $collectionMock->expects($this->once())
85-
// ->method('addFieldToFilter')
86-
// ->with('country_id', ['in' => ['AM' => 'AM']]);
87-
//
88-
// $this->assertEquals(
89-
// $collectionMock,
90-
// $this->countryHandler->loadByScope($collectionMock, 1, ScopeInterface::SCOPE_WEBSITE)
91-
// );
92-
// }
9373
}

0 commit comments

Comments
 (0)