Skip to content
Snippets Groups Projects
Commit 863c05a9 authored by Sergii Kovalenko's avatar Sergii Kovalenko
Browse files

MAGETWO-56941: [Github] Allowed countries for customer address in admin using...

MAGETWO-56941: [Github] Allowed countries for customer address in admin using storeview configuration #2946
parent fe86a0a6
Branches
No related merge requests found
......@@ -44,6 +44,8 @@ class AllowedCountries
* @param \Magento\Directory\Model\AllowedCountries $subject
* @param string | null $filter
* @param string $scope
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeGetAllowedCountries(
\Magento\Directory\Model\AllowedCountries $subject,
......
......@@ -43,11 +43,13 @@ class CountryWithWebsites extends \Magento\Eav\Model\Entity\Attribute\Source\Tab
private $shareConfig;
/**
* CountryWithWebsites constructor.
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory
* @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countriesFactory
* @param AllowedCountries $allowedCountriesReader
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param Share $shareConfig
*/
public function __construct(
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory,
......@@ -89,7 +91,6 @@ class CountryWithWebsites extends \Magento\Eav\Model\Entity\Attribute\Source\Tab
$allowedCountries = $this->allowedCountriesReader->getAllowedCountries();
}
$this->options = $this->createCountriesCollection()
->addFieldToFilter('country_id', ['in' => $allowedCountries])
->toOptionArray();
......
......@@ -60,7 +60,8 @@ class UpgradeData implements UpgradeDataInterface
CustomerSetupFactory $customerSetupFactory,
IndexerRegistry $indexerRegistry,
\Magento\Eav\Model\Config $eavConfig
) {
)
{
$this->customerSetupFactory = $customerSetupFactory;
$this->indexerRegistry = $indexerRegistry;
$this->eavConfig = $eavConfig;
......@@ -189,6 +190,19 @@ class UpgradeData implements UpgradeDataInterface
return $countries;
}
/**
* Retrieve countries not depending on global scope
*
* @param string $scope
* @param int $scopeCode
* @return array
*/
private function getAllowedCountries($scope, $scopeCode)
{
$reader = $this->getAllowedCountriesReader();
return $reader->makeCountriesUnique($reader->getCountriesFromConfig($scope, $scopeCode));
}
/**
* Merge allowed countries from stores to websites
*
......@@ -202,8 +216,7 @@ class UpgradeData implements UpgradeDataInterface
foreach ($this->getStoreManager()->getStores() as $store) {
$allowedCountries = $this->mergeAllowedCountries(
$allowedCountries,
$this->getAllowedCountriesReader()
->getAllowedCountries(ScopeInterface::SCOPE_STORE, $store->getId()),
$this->getAllowedCountries(ScopeInterface::SCOPE_STORE, $store->getId()),
$store->getWebsiteId()
);
}
......@@ -211,8 +224,7 @@ class UpgradeData implements UpgradeDataInterface
foreach ($this->getStoreManager()->getWebsites() as $website) {
$allowedCountries = $this->mergeAllowedCountries(
$allowedCountries,
$this->getAllowedCountriesReader()
->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE, $website->getId()),
$this->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE, $website->getId()),
$website->getId()
);
}
......
......@@ -56,8 +56,8 @@ class AllowedCountriesTest extends \PHPUnit_Framework_TestCase
->willReturn([$websiteMock]);
$this->assertEquals(
[[$expectedFilter], $expectedScope],
[$expectedScope, [$expectedFilter]],
$this->plugin->beforeGetAllowedCountries($originalAllowedCountriesMock)
);
}
}
\ No newline at end of file
}
......@@ -93,12 +93,12 @@ class CountryWithWebsitesTest extends \PHPUnit_Framework_TestCase
$this->allowedCountriesMock->expects($this->exactly(2))
->method('getAllowedCountries')
->withConsecutive(
[1, 'website'],
[2, 'website']
['website', 1],
['website', 2]
)
->willReturnMap([
[1, 'website', ['AM' => 'AM']],
[2, 'website', ['AM' => 'AM', 'DZ' => 'DZ']]
['website', 1, ['AM' => 'AM']],
['website', 2, ['AM' => 'AM', 'DZ' => 'DZ']]
]);
$this->countriesFactoryMock->expects($this->once())
->method('create')
......
......@@ -71,14 +71,14 @@ class AllowedCountries
$allowedCountries = $this->getCountriesFromConfig($scope, $scopeCode);
}
return $this->getUniqueCountries($allowedCountries);
return $this->makeCountriesUnique($allowedCountries);
}
/**
* Resolve scope code by scope
*
* @throws \InvalidArgumentException
* @param $scope
* @param string $scope
* @return array|int
*/
private function getDefaultScopeCode($scope)
......@@ -105,7 +105,7 @@ class AllowedCountries
* @param array $allowedCountries
* @return array
*/
private function getUniqueCountries(array $allowedCountries)
public function makeCountriesUnique(array $allowedCountries)
{
return array_combine($allowedCountries, $allowedCountries);
}
......@@ -117,7 +117,7 @@ class AllowedCountries
* @param int $scopeCode
* @return array
*/
private function getCountriesFromConfig($scope, $scopeCode)
public function getCountriesFromConfig($scope, $scopeCode)
{
return explode(
',',
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment