Skip to content

Commit f24bd27

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

File tree

9 files changed

+59
-18
lines changed

9 files changed

+59
-18
lines changed

app/code/Magento/Directory/Model/CountryHandler.php renamed to app/code/Magento/Customer/Model/CountryHandler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace Magento\Directory\Model;
7+
namespace Magento\Customer\Model;
88

99
use Magento\Customer\Model\Config\Share;
1010
use Magento\Framework\App\Config\ScopeConfigInterface;
@@ -15,6 +15,10 @@
1515
use Magento\Store\Model\StoreManagerInterface;
1616
use Magento\Store\Model\Website;
1717

18+
/**
19+
* Class CountryHandler.
20+
* @package Magento\Customer\Model
21+
*/
1822
class CountryHandler
1923
{
2024
const ALLOWED_COUNTRIES_PATH = 'general/country/allow';

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
*/
1212
namespace Magento\Customer\Model\ResourceModel\Address\Attribute\Source;
1313

14+
use Magento\Checkout\Model\Session;
15+
use Magento\Framework\App\ObjectManager;
16+
use Magento\Store\Model\StoreManagerInterface;
17+
1418
class Country extends \Magento\Eav\Model\Entity\Attribute\Source\Table
1519
{
1620
/**
@@ -41,17 +45,49 @@ public function getAllOptions()
4145
{
4246
if (!$this->_options) {
4347
$this->_options = $this->_createCountriesCollection()->loadByStore(
44-
$this->getAttribute()->getStoreId()
48+
$this->resolveStoreId()
4549
)->toOptionArray();
4650
}
4751
return $this->_options;
4852
}
4953

54+
/**
55+
* @deprecated
56+
* @return \Magento\Backend\Model\Session\Quote
57+
*/
58+
private function getBackendSession()
59+
{
60+
return ObjectManager::getInstance()->get(\Magento\Backend\Model\Session\Quote::class);
61+
}
62+
63+
/**
64+
* Retrieve store id in view of backend quote.
65+
* @return int
66+
*/
67+
private function resolveStoreId()
68+
{
69+
$backendSession = $this->getBackendSession();
70+
if ($backendSession->getQuoteId() && $backendSession->getQuote()->hasStoreId()) {
71+
return $backendSession->getQuote()->getStoreId();
72+
}
73+
74+
return $this->getStoreManager()->getStore()->getId();
75+
}
76+
5077
/**
5178
* @return \Magento\Directory\Model\ResourceModel\Country\Collection
5279
*/
5380
protected function _createCountriesCollection()
5481
{
5582
return $this->_countriesFactory->create();
5683
}
84+
85+
/**
86+
* @deprecated
87+
* @return StoreManagerInterface
88+
*/
89+
private function getStoreManager()
90+
{
91+
return ObjectManager::getInstance()->get(StoreManagerInterface::class);
92+
}
5793
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CountryByWebsite extends \Magento\Eav\Model\Entity\Attribute\Source\Table
2626
private $countriesFactory;
2727

2828
/**
29-
* @var \Magento\Directory\Model\CountryHandler
29+
* @var \Magento\Customer\Model\CountryHandler
3030
*/
3131
private $countryHandler;
3232

@@ -49,7 +49,7 @@ public function __construct(
4949
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory,
5050
\Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory,
5151
\Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countriesFactory,
52-
\Magento\Directory\Model\CountryHandler $countryHandler,
52+
\Magento\Customer\Model\CountryHandler $countryHandler,
5353
\Magento\Store\Model\StoreManagerInterface $storeManager
5454
)
5555
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Magento\Customer\Setup;
88

99
use Magento\Customer\Model\Customer;
10-
use Magento\Directory\Model\CountryHandler;
10+
use Magento\Customer\Model\CountryHandler;
1111
use Magento\Framework\App\Config\ScopeConfigInterface;
1212
use Magento\Framework\Encryption\Encryptor;
1313
use Magento\Framework\Indexer\IndexerRegistry;

app/code/Magento/Directory/Test/Unit/Model/CountryHandlerTest.php renamed to app/code/Magento/Customer/Test/Unit/Model/CountryHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Magento\Directory\Test\Unit\Model;
88

99
use Magento\Customer\Model\Config\Share;
10-
use Magento\Directory\Model\CountryHandler;
10+
use Magento\Customer\Model\CountryHandler;
1111
use Magento\Framework\App\Config\ScopeConfigInterface;
1212
use Magento\Framework\Data\Collection\AbstractDb;
1313
use Magento\Store\Api\Data\WebsiteInterface;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace Magento\Customer\Test\Unit\Model\ResourceModel\Address\Attribute\Backend;
7+
namespace Magento\Customer\Test\Unit\Model\ResourceModel\Address\Attribute\Source;
88

99
use Magento\Customer\Model\ResourceModel\Address\Attribute\Source\CountryByWebsite;
10-
use Magento\Directory\Model\CountryHandler;
10+
use Magento\Customer\Model\CountryHandler;
1111
use Magento\Framework\Data\Collection\AbstractDb;
1212
use Magento\Store\Api\Data\WebsiteInterface;
1313
use Magento\Store\Model\StoreManagerInterface;
@@ -20,7 +20,7 @@ class CountryByWebsiteTest extends \PHPUnit_Framework_TestCase
2020
private $countriesFactoryMock;
2121

2222
/**
23-
* @var \Magento\Directory\Model\CountryHandler | \PHPUnit_Framework_MockObject_MockObject
23+
* @var \Magento\Customer\Model\CountryHandler | \PHPUnit_Framework_MockObject_MockObject
2424
*/
2525
private $countryHandlerMock;
2626

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

Lines changed: 1 addition & 1 deletion
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\Directory\Model\CountryHandler;
13+
use Magento\Customer\Model\CountryHandler;
1414
use Magento\Framework\App\ObjectManager;
1515
use Magento\Store\Model\ScopeInterface;
1616

app/code/Magento/Ui/view/base/web/js/form/element/country.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@ define([
2525
* @param {String} field
2626
*/
2727
filter: function (value, field) {
28+
var result;
2829
if (!field) { //validate field, if we are on update
2930
field = this.filterBy.field;
3031
}
3132

3233
this._super(value, field);
3334

34-
var result = _.filter(this.initialOptions, function (item) {
35+
result = _.filter(this.initialOptions, function (item) {
3536
if (item[field]) {
3637
return ~item[field].indexOf(value);
3738
}
3839

3940
return false;
4041
});
41-
42+
4243
this.setOptions(result);
4344
}
4445
});

app/code/Magento/Ui/view/base/web/js/form/element/website.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ define([
1616
isGlobalScope: 0
1717
},
1818

19+
/**
20+
* Website component constructor.
21+
* @returns {exports}
22+
*/
1923
initialize: function () {
2024
this._super();
21-
22-
if (this.isGlobalScope) {
23-
this.setVisible(false);
24-
}
25-
26-
if (this.customerId) { //disable element if customer exists
25+
26+
if (this.customerId || this.isGlobalScope) { //disable element if customer exists
2727
this.disable(true);
2828
}
2929

0 commit comments

Comments
 (0)