Skip to content

Commit

Permalink
MAGETWO-56941: CLONE - CLONE - [Github] Allowed countries for custome…
Browse files Browse the repository at this point in the history
…r address in admin using storeview configuration #2946
  • Loading branch information
Sergii Kovalenko committed Aug 22, 2016
1 parent 1b4ba9f commit f24bd27
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See COPYING.txt for license details.
*/

namespace Magento\Directory\Model;
namespace Magento\Customer\Model;

use Magento\Customer\Model\Config\Share;
use Magento\Framework\App\Config\ScopeConfigInterface;
Expand All @@ -15,6 +15,10 @@
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Model\Website;

/**
* Class CountryHandler.
* @package Magento\Customer\Model
*/
class CountryHandler
{
const ALLOWED_COUNTRIES_PATH = 'general/country/allow';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*/
namespace Magento\Customer\Model\ResourceModel\Address\Attribute\Source;

use Magento\Checkout\Model\Session;
use Magento\Framework\App\ObjectManager;
use Magento\Store\Model\StoreManagerInterface;

class Country extends \Magento\Eav\Model\Entity\Attribute\Source\Table
{
/**
Expand Down Expand Up @@ -41,17 +45,49 @@ public function getAllOptions()
{
if (!$this->_options) {
$this->_options = $this->_createCountriesCollection()->loadByStore(
$this->getAttribute()->getStoreId()
$this->resolveStoreId()
)->toOptionArray();
}
return $this->_options;
}

/**
* @deprecated
* @return \Magento\Backend\Model\Session\Quote
*/
private function getBackendSession()
{
return ObjectManager::getInstance()->get(\Magento\Backend\Model\Session\Quote::class);
}

/**
* Retrieve store id in view of backend quote.
* @return int
*/
private function resolveStoreId()
{
$backendSession = $this->getBackendSession();
if ($backendSession->getQuoteId() && $backendSession->getQuote()->hasStoreId()) {
return $backendSession->getQuote()->getStoreId();
}

return $this->getStoreManager()->getStore()->getId();
}

/**
* @return \Magento\Directory\Model\ResourceModel\Country\Collection
*/
protected function _createCountriesCollection()
{
return $this->_countriesFactory->create();
}

/**
* @deprecated
* @return StoreManagerInterface
*/
private function getStoreManager()
{
return ObjectManager::getInstance()->get(StoreManagerInterface::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CountryByWebsite extends \Magento\Eav\Model\Entity\Attribute\Source\Table
private $countriesFactory;

/**
* @var \Magento\Directory\Model\CountryHandler
* @var \Magento\Customer\Model\CountryHandler
*/
private $countryHandler;

Expand All @@ -49,7 +49,7 @@ public function __construct(
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory,
\Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory,
\Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countriesFactory,
\Magento\Directory\Model\CountryHandler $countryHandler,
\Magento\Customer\Model\CountryHandler $countryHandler,
\Magento\Store\Model\StoreManagerInterface $storeManager
)
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Magento\Customer\Setup;

use Magento\Customer\Model\Customer;
use Magento\Directory\Model\CountryHandler;
use Magento\Customer\Model\CountryHandler;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Encryption\Encryptor;
use Magento\Framework\Indexer\IndexerRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Magento\Directory\Test\Unit\Model;

use Magento\Customer\Model\Config\Share;
use Magento\Directory\Model\CountryHandler;
use Magento\Customer\Model\CountryHandler;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Store\Api\Data\WebsiteInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* See COPYING.txt for license details.
*/

namespace Magento\Customer\Test\Unit\Model\ResourceModel\Address\Attribute\Backend;
namespace Magento\Customer\Test\Unit\Model\ResourceModel\Address\Attribute\Source;

use Magento\Customer\Model\ResourceModel\Address\Attribute\Source\CountryByWebsite;
use Magento\Directory\Model\CountryHandler;
use Magento\Customer\Model\CountryHandler;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Store\Api\Data\WebsiteInterface;
use Magento\Store\Model\StoreManagerInterface;
Expand All @@ -20,7 +20,7 @@ class CountryByWebsiteTest extends \PHPUnit_Framework_TestCase
private $countriesFactoryMock;

/**
* @var \Magento\Directory\Model\CountryHandler | \PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Customer\Model\CountryHandler | \PHPUnit_Framework_MockObject_MockObject
*/
private $countryHandlerMock;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Directory Country Resource Collection
*/
namespace Magento\Directory\Model\ResourceModel\Country;
use Magento\Directory\Model\CountryHandler;
use Magento\Customer\Model\CountryHandler;
use Magento\Framework\App\ObjectManager;
use Magento\Store\Model\ScopeInterface;

Expand Down
5 changes: 3 additions & 2 deletions app/code/Magento/Ui/view/base/web/js/form/element/country.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ define([
* @param {String} field
*/
filter: function (value, field) {
var result;
if (!field) { //validate field, if we are on update
field = this.filterBy.field;
}

this._super(value, field);

var result = _.filter(this.initialOptions, function (item) {
result = _.filter(this.initialOptions, function (item) {
if (item[field]) {
return ~item[field].indexOf(value);
}

return false;
});

this.setOptions(result);
}
});
Expand Down
12 changes: 6 additions & 6 deletions app/code/Magento/Ui/view/base/web/js/form/element/website.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ define([
isGlobalScope: 0
},

/**
* Website component constructor.
* @returns {exports}
*/
initialize: function () {
this._super();

if (this.isGlobalScope) {
this.setVisible(false);
}

if (this.customerId) { //disable element if customer exists

if (this.customerId || this.isGlobalScope) { //disable element if customer exists
this.disable(true);
}

Expand Down

0 comments on commit f24bd27

Please sign in to comment.