From 8b292abdd93eac78852142940a7ce31c87b11b4b Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Thu, 12 Aug 2021 19:51:27 +0530 Subject: [PATCH 01/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settingslugin beforeGetAllowedCountries removed for preserving original behaviour of function getAllowedCountries -P --- app/code/Magento/Customer/etc/di.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/code/Magento/Customer/etc/di.xml b/app/code/Magento/Customer/etc/di.xml index 06e986b8d7daa..13c0fd0a38ede 100644 --- a/app/code/Magento/Customer/etc/di.xml +++ b/app/code/Magento/Customer/etc/di.xml @@ -355,9 +355,6 @@ - - - From 433d55bf8d779f3fe0ba38beda401162e1da73c7 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Thu, 12 Aug 2021 20:18:41 +0530 Subject: [PATCH 02/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - plugin beforeGetAllowedCountries removed for preserving original behaviour of function getAllowedCountries with it's source code file -P --- .../Model/Plugin/AllowedCountries.php | 65 ------------------ .../Model/Plugin/AllowedCountriesTest.php | 67 ------------------- 2 files changed, 132 deletions(-) delete mode 100644 app/code/Magento/Customer/Model/Plugin/AllowedCountries.php delete mode 100644 app/code/Magento/Customer/Test/Unit/Model/Plugin/AllowedCountriesTest.php diff --git a/app/code/Magento/Customer/Model/Plugin/AllowedCountries.php b/app/code/Magento/Customer/Model/Plugin/AllowedCountries.php deleted file mode 100644 index dff162d826b6d..0000000000000 --- a/app/code/Magento/Customer/Model/Plugin/AllowedCountries.php +++ /dev/null @@ -1,65 +0,0 @@ -shareConfig = $share; - $this->storeManager = $storeManager; - } - - /** - * Retrieve all allowed countries or specific by scope depends on customer share setting - * - * @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, - $scope = ScopeInterface::SCOPE_WEBSITE, - $scopeCode = null - ) { - if ($this->shareConfig->isGlobalScope()) { - //Check if we have shared accounts - than merge all website allowed countries - $scopeCode = array_map(function (WebsiteInterface $website) { - return $website->getId(); - }, $this->storeManager->getWebsites()); - $scope = ScopeInterface::SCOPE_WEBSITES; - } - - return [$scope, $scopeCode]; - } -} diff --git a/app/code/Magento/Customer/Test/Unit/Model/Plugin/AllowedCountriesTest.php b/app/code/Magento/Customer/Test/Unit/Model/Plugin/AllowedCountriesTest.php deleted file mode 100644 index d8e28c55a7457..0000000000000 --- a/app/code/Magento/Customer/Test/Unit/Model/Plugin/AllowedCountriesTest.php +++ /dev/null @@ -1,67 +0,0 @@ -shareConfig = $this->getMockBuilder(Share::class) - ->disableOriginalConstructor() - ->getMock(); - $this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class); - - $this->plugin = new AllowedCountries($this->shareConfig, $this->storeManager); - } - - public function testGetAllowedCountriesWithGlobalScope() - { - $expectedFilter = 1; - $expectedScope = ScopeInterface::SCOPE_WEBSITES; - - $this->shareConfig->expects($this->once()) - ->method('isGlobalScope') - ->willReturn(true); - $originalAllowedCountriesMock = $this->getMockBuilder(\Magento\Directory\Model\AllowedCountries::class) - ->disableOriginalConstructor() - ->getMock(); - $websiteMock = $this->getMockForAbstractClass(WebsiteInterface::class); - $websiteMock->expects($this->once()) - ->method('getId') - ->willReturn($expectedFilter); - $this->storeManager->expects($this->once()) - ->method('getWebsites') - ->willReturn([$websiteMock]); - - $this->assertEquals( - [$expectedScope, [$expectedFilter]], - $this->plugin->beforeGetAllowedCountries($originalAllowedCountriesMock) - ); - } -} From 1478809aae68695a1cca5bf0cf8f345fa7010d58 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Mon, 16 Aug 2021 11:51:49 +0530 Subject: [PATCH 03/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Unit test coverage testGetAllowedCountriesWithGlobalScope done -P --- .../Test/Unit/Model/AllowedCountriesTest.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/app/code/Magento/Directory/Test/Unit/Model/AllowedCountriesTest.php b/app/code/Magento/Directory/Test/Unit/Model/AllowedCountriesTest.php index ab16e83c2bf5d..95c28d3221740 100644 --- a/app/code/Magento/Directory/Test/Unit/Model/AllowedCountriesTest.php +++ b/app/code/Magento/Directory/Test/Unit/Model/AllowedCountriesTest.php @@ -7,6 +7,7 @@ namespace Magento\Directory\Test\Unit\Model; +use Magento\Customer\Model\Config\Share; use Magento\Directory\Model\AllowedCountries; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Api\Data\WebsiteInterface; @@ -32,11 +33,19 @@ class AllowedCountriesTest extends TestCase */ private $allowedCountriesReader; + /** + * @var Share|MockObject + */ + private $shareConfigMock; + /** * Test setUp */ protected function setUp(): void { + $this->shareConfigMock = $this->getMockBuilder(Share::class) + ->disableOriginalConstructor() + ->getMock(); $this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class); $this->storeManagerMock = $this->getMockForAbstractClass(StoreManagerInterface::class); @@ -100,4 +109,35 @@ public function testGetAllowedCountriesDefaultScope() $this->allowedCountriesReader->getAllowedCountries(ScopeInterface::SCOPE_STORE, 0) ); } + + /** + * Test for getAllowedCountries with global scope + */ + public function testGetAllowedCountriesWithGlobalScope() + { + $expectedFilter = 1; + $expectedScope = ScopeInterface::SCOPE_WEBSITES; + + $this->shareConfigMock->expects($this->once()) + ->method('isGlobalScope') + ->willReturn(true); + if ($this->shareConfigMock->isGlobalScope()) { + + $websiteMock = $this->getMockForAbstractClass(WebsiteInterface::class); + $websiteMock->expects($this->once()) + ->method('getId') + ->willReturn($expectedFilter); + + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->with(AllowedCountries::ALLOWED_COUNTRIES_PATH, 'website', $websiteMock->getId()) + ->willReturn('AM'); + + //$scopeCode should have single valued array only eg:[1] + $this->assertEquals( + ['AM' => 'AM'], + $this->allowedCountriesReader->getAllowedCountries($expectedScope, [$expectedFilter]) + ); + } + } } From 7e45c84ea29ef488dc2fdd29d73894da19978277 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Mon, 6 Sep 2021 16:55:34 +0530 Subject: [PATCH 04/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Saved address shouldn't populate to the checkout if belongs to different country. --- .../Address/CustomerAddressDataProvider.php | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/Address/CustomerAddressDataProvider.php b/app/code/Magento/Customer/Model/Address/CustomerAddressDataProvider.php index 04fdd2a7f7266..4334607c6b175 100644 --- a/app/code/Magento/Customer/Model/Address/CustomerAddressDataProvider.php +++ b/app/code/Magento/Customer/Model/Address/CustomerAddressDataProvider.php @@ -7,6 +7,10 @@ namespace Magento\Customer\Model\Address; +use Magento\Customer\Model\Config\Share; +use Magento\Directory\Model\AllowedCountries; +use Magento\Framework\App\ObjectManager; + /** * Provides customer address data. */ @@ -24,13 +28,31 @@ class CustomerAddressDataProvider */ private $customerAddressDataFormatter; + /** + * @var \Magento\Customer\Model\Config\Share + */ + private $shareConfig; + + /** + * @var AllowedCountries + */ + private $allowedCountryReader; + /** * @param CustomerAddressDataFormatter $customerAddressDataFormatter + * @param Share|null $share + * @param AllowedCountries|null $allowedCountryReader */ public function __construct( - CustomerAddressDataFormatter $customerAddressDataFormatter + CustomerAddressDataFormatter $customerAddressDataFormatter, + ?Share $share = null, + ?AllowedCountries $allowedCountryReader = null ) { $this->customerAddressDataFormatter = $customerAddressDataFormatter; + $this->shareConfig = $share ?: ObjectManager::getInstance() + ->get(Share::class); + $this->allowedCountryReader = $allowedCountryReader ?: ObjectManager::getInstance() + ->get(AllowedCountries::class); } /** @@ -52,8 +74,14 @@ public function getAddressDataByCustomer( return []; } + $allowedCountries = $this->allowedCountryReader->getAllowedCountries(); $customerAddresses = []; foreach ($customerOriginAddresses as $address) { + // Checks if a country id present in the allowed countries list. + if ($this->shareConfig->isGlobalScope() && !in_array($address->getCountryId(), $allowedCountries)) { + continue; + } + $customerAddresses[$address->getId()] = $this->customerAddressDataFormatter->prepareAddress($address); } From bc38677454829c958dd03bdc3182fc1d1836c870 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Wed, 8 Sep 2021 08:43:58 +0530 Subject: [PATCH 05/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Only corresponding address should be populated in admin too --- .../ResourceModel/Address/Collection.php | 40 ++++++++++++++++++- .../templates/order/create/form/address.phtml | 3 +- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/Collection.php b/app/code/Magento/Customer/Model/ResourceModel/Address/Collection.php index a26228ccc9062..8c1a1b9499ba5 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/Collection.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/Collection.php @@ -5,6 +5,11 @@ */ namespace Magento\Customer\Model\ResourceModel\Address; +use Magento\Customer\Model\Config\Share; +use Magento\Store\Model\ScopeInterface; +use Magento\Directory\Model\AllowedCountries; +use Magento\Framework\App\ObjectManager; + /** * Customers collection * @@ -14,14 +19,31 @@ */ class Collection extends \Magento\Eav\Model\Entity\Collection\VersionControl\AbstractCollection { + /** + * @var \Magento\Customer\Model\Config\Share + */ + private $shareConfig; + + /** + * @var AllowedCountries + */ + private $allowedCountryReader; + /** * Resource initialization * * @return void */ - protected function _construct() + protected function _construct( + ?Share $share = null, + ?AllowedCountries $allowedCountryReader = null + ) { $this->_init(\Magento\Customer\Model\Address::class, \Magento\Customer\Model\ResourceModel\Address::class); + $this->shareConfig = $share ?: ObjectManager::getInstance() + ->get(Share::class); + $this->allowedCountryReader = $allowedCountryReader ?: ObjectManager::getInstance() + ->get(AllowedCountries::class); } /** @@ -41,4 +63,20 @@ public function setCustomerFilter($customer) } return $this; } + + /** + * Set store filter + * + * @param \Magento\Store\Model\Store|integer $storeId + * @return $this + */ + public function setScopeFilter($storeId) + { + // Checks if a country present in the allowed countries list. + $allowedCountries = $this->allowedCountryReader->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId); + if ($this->shareConfig->isGlobalScope()) { + $this->addAttributeToFilter('country_id', ['in' => $allowedCountries]); + } + return $this; + } } diff --git a/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml b/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml index 79bc1e3a8df36..95e04c027d721 100644 --- a/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml +++ b/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml @@ -16,7 +16,8 @@ $addressCollection = $block->getData('customerAddressCollection'); $addressArray = []; if ($block->getCustomerId()): - $addressArray = $addressCollection->setCustomerFilter([$block->getCustomerId()])->toArray(); + $addressArray = $addressCollection->setCustomerFilter([$block->getCustomerId()]) + ->setScopeFilter($block->getStoreId())->toArray(); endif; /** From a619f4adab389189a861a6bb2d921c603621d792 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Wed, 8 Sep 2021 12:09:51 +0530 Subject: [PATCH 06/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Only corresponding address should be populated in admin too --- .../Customer/Model/ResourceModel/Address/Collection.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/Collection.php b/app/code/Magento/Customer/Model/ResourceModel/Address/Collection.php index 8c1a1b9499ba5..884fd7b7d726a 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/Collection.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/Collection.php @@ -32,13 +32,15 @@ class Collection extends \Magento\Eav\Model\Entity\Collection\VersionControl\Abs /** * Resource initialization * + * @param Share|null $share + * @param AllowedCountries|null $allowedCountryReader + * * @return void */ protected function _construct( ?Share $share = null, ?AllowedCountries $allowedCountryReader = null - ) - { + ) { $this->_init(\Magento\Customer\Model\Address::class, \Magento\Customer\Model\ResourceModel\Address::class); $this->shareConfig = $share ?: ObjectManager::getInstance() ->get(Share::class); From ed32f4735d0e8f34e0a027441a897fb9af287e18 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Fri, 10 Sep 2021 15:53:37 +0530 Subject: [PATCH 07/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage written for customerAddressDataProvider --- .../CustomerAddressDataProviderTest.php | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php new file mode 100644 index 0000000000000..a39744a1af712 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php @@ -0,0 +1,124 @@ +objectManager = Bootstrap::getObjectManager(); + $this->customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class); + $this->addressDataProvider = $this->objectManager->create(CustomerAddressDataProvider::class); + } + + /** + * Ensure that config changes are deleted or restored. + */ + protected function tearDown(): void + { + /** @var \Magento\Framework\Registry $registry */ + $registry = $this->objectManager->get(\Magento\Framework\Registry::class); + $registry->unregister('isSecureArea'); + $registry->register('isSecureArea', true); + + /** @var ConfigInterface $config */ + $config = $this->objectManager->get(ConfigInterface::class); + $config->deleteConfig('general/country/allow'); + $this->objectManager->get(ReinitableConfigInterface::class)->reinit(); + + /** @var Writer $configWriter */ + $configWriter = $this->objectManager->get(WriterInterface::class); + + $configWriter->save('customer/account_share/scope', 1); + $scopeConfig = $this->objectManager->get(ScopeConfigInterface::class); + $scopeConfig->clean(); + + $registry->unregister('isSecureArea'); + $registry->register('isSecureArea', false); + parent::tearDown(); + } + + /** + * Assert that only allowed country address fetched. + * + * @magentoDataFixture Magento/Customer/_files/customer.php + * @magentoDataFixture Magento/Customer/_files/customer_address.php + * + * @dataProvider createAddressesDataProvider + * + * @return void + */ + public function testGetAddressDataByCustomerForAllowedCountries($customerId, $allowedCountries) : void + { + /** @var ConfigInterface $config */ + $config = $this->objectManager->get(ConfigInterface::class); + $config->saveConfig('general/country/allow', implode(',', $allowedCountries)); + $this->objectManager->get(ReinitableConfigInterface::class)->reinit(); + + /** @var Writer $configWriter */ + $configWriter = $this->objectManager->get(WriterInterface::class); + $configWriter->save('customer/account_share/scope', 0); + $scopeConfig = $this->objectManager->get(ScopeConfigInterface::class); + $scopeConfig->clean(); + + $customer = $this->customerRepository->getById($customerId); + $addresses = $this->addressDataProvider->getAddressDataByCustomer($customer); + + $this->assertIsArray($addresses); + + foreach ($addresses as $address) { + $this->assertContains($address['country_id'], $allowedCountries); + } + } + + + + /** + * Data provider for create default or not default address. + * + * @return array + */ + public function createAddressesDataProvider(): array + { + return [ + 'address_in_single_allowed_country' => [1, ['US']], + 'address_not_in_single_allowed_country' => [1, ['FR']], + 'address_in_multiple_allowed_countries' => [1, ['US', 'IN']], + 'address_not_in_multiple_allowed_countries' => [1, ['FR', 'DE']], + ]; + } +} From 98c1fc179fbde614481e7172d6056f59c043ebcb Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Fri, 10 Sep 2021 15:55:40 +0530 Subject: [PATCH 08/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage written for customerAddressDataProvider --- .../Customer/Model/Address/CustomerAddressDataProviderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php index a39744a1af712..0ba94e341ce69 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php @@ -108,7 +108,7 @@ public function testGetAddressDataByCustomerForAllowedCountries($customerId, $al /** - * Data provider for create default or not default address. + * Data provider for create allowed or not allowed countries. * * @return array */ From 973743bf0036a0dc1bc43605999cdbeabb2f4da5 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Fri, 10 Sep 2021 16:03:52 +0530 Subject: [PATCH 09/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage written for customerAddressDataProvider --- .../Customer/Model/Address/CustomerAddressDataProviderTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php index 0ba94e341ce69..f2fece778faff 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php @@ -8,6 +8,7 @@ namespace Magento\Customer\Model\Address; use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\ObjectManager; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Framework\App\Config\ConfigResource\ConfigInterface; use Magento\Framework\App\Config\ReinitableConfigInterface; From 580e739264156d8a11e887981066d7cdffb00511 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Fri, 10 Sep 2021 18:18:10 +0530 Subject: [PATCH 10/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Updated for backward compatibility issues --- .../ResourceModel/Address/Collection.php | 44 +------------------ .../templates/order/create/form/address.phtml | 3 +- .../CustomerAddressDataProviderTest.php | 2 - 3 files changed, 3 insertions(+), 46 deletions(-) diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/Collection.php b/app/code/Magento/Customer/Model/ResourceModel/Address/Collection.php index 884fd7b7d726a..a26228ccc9062 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/Collection.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/Collection.php @@ -5,11 +5,6 @@ */ namespace Magento\Customer\Model\ResourceModel\Address; -use Magento\Customer\Model\Config\Share; -use Magento\Store\Model\ScopeInterface; -use Magento\Directory\Model\AllowedCountries; -use Magento\Framework\App\ObjectManager; - /** * Customers collection * @@ -19,33 +14,14 @@ */ class Collection extends \Magento\Eav\Model\Entity\Collection\VersionControl\AbstractCollection { - /** - * @var \Magento\Customer\Model\Config\Share - */ - private $shareConfig; - - /** - * @var AllowedCountries - */ - private $allowedCountryReader; - /** * Resource initialization * - * @param Share|null $share - * @param AllowedCountries|null $allowedCountryReader - * * @return void */ - protected function _construct( - ?Share $share = null, - ?AllowedCountries $allowedCountryReader = null - ) { + protected function _construct() + { $this->_init(\Magento\Customer\Model\Address::class, \Magento\Customer\Model\ResourceModel\Address::class); - $this->shareConfig = $share ?: ObjectManager::getInstance() - ->get(Share::class); - $this->allowedCountryReader = $allowedCountryReader ?: ObjectManager::getInstance() - ->get(AllowedCountries::class); } /** @@ -65,20 +41,4 @@ public function setCustomerFilter($customer) } return $this; } - - /** - * Set store filter - * - * @param \Magento\Store\Model\Store|integer $storeId - * @return $this - */ - public function setScopeFilter($storeId) - { - // Checks if a country present in the allowed countries list. - $allowedCountries = $this->allowedCountryReader->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId); - if ($this->shareConfig->isGlobalScope()) { - $this->addAttributeToFilter('country_id', ['in' => $allowedCountries]); - } - return $this; - } } diff --git a/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml b/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml index 95e04c027d721..79bc1e3a8df36 100644 --- a/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml +++ b/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml @@ -16,8 +16,7 @@ $addressCollection = $block->getData('customerAddressCollection'); $addressArray = []; if ($block->getCustomerId()): - $addressArray = $addressCollection->setCustomerFilter([$block->getCustomerId()]) - ->setScopeFilter($block->getStoreId())->toArray(); + $addressArray = $addressCollection->setCustomerFilter([$block->getCustomerId()])->toArray(); endif; /** diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php index f2fece778faff..12fa4ed809bf3 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php @@ -106,8 +106,6 @@ public function testGetAddressDataByCustomerForAllowedCountries($customerId, $al } } - - /** * Data provider for create allowed or not allowed countries. * From 48c686c3fe35b89a50143eee4949271e38072953 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Mon, 13 Sep 2021 14:43:50 +0530 Subject: [PATCH 11/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - New Plugin (AllowedCountriesAddressFilter )introduced --- .../Plugin/AllowedCountriesAddressFilter.php | 60 +++++++++++++++++++ app/code/Magento/Customer/etc/di.xml | 3 + 2 files changed, 63 insertions(+) create mode 100644 app/code/Magento/Customer/Model/Plugin/AllowedCountriesAddressFilter.php diff --git a/app/code/Magento/Customer/Model/Plugin/AllowedCountriesAddressFilter.php b/app/code/Magento/Customer/Model/Plugin/AllowedCountriesAddressFilter.php new file mode 100644 index 0000000000000..2e4a4d8df8c01 --- /dev/null +++ b/app/code/Magento/Customer/Model/Plugin/AllowedCountriesAddressFilter.php @@ -0,0 +1,60 @@ +allowedCountryReader = $allowedCountryReader; + $this->addressBlock = $addressBlock; + } + + /** + * Filter customer saved addresses by allowed countries of their store. + * + * @param \Magento\Customer\Model\ResourceModel\Address\Collection $subject + * @param \Magento\Customer\Model\Customer|array $customer + * @return $this + */ + public function beforeSetCustomerFilter(Collection $subject, $customer) + { + $storeId = $this->addressBlock->getStoreId() ?? null; + if ($storeId) { + $allowedCountries = $this->allowedCountryReader->getAllowedCountries( + ScopeInterface::SCOPE_STORE, + $storeId + ); + + $subject->addAttributeToFilter('country_id', ['in' => $allowedCountries]); + } + } +} diff --git a/app/code/Magento/Customer/etc/di.xml b/app/code/Magento/Customer/etc/di.xml index 156986b7b4a3c..5e07a7aeb1f62 100644 --- a/app/code/Magento/Customer/etc/di.xml +++ b/app/code/Magento/Customer/etc/di.xml @@ -366,6 +366,9 @@ + + + From caa0c178f4a8a673c955ae40b9c97d304dd771ed Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Mon, 13 Sep 2021 18:33:57 +0530 Subject: [PATCH 12/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - New Plugin (AllowedCountriesAddressFilter ) updated --- .../Model/Plugin/AllowedCountriesAddressFilter.php | 7 +------ app/etc/di.xml | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Customer/Model/Plugin/AllowedCountriesAddressFilter.php b/app/code/Magento/Customer/Model/Plugin/AllowedCountriesAddressFilter.php index 2e4a4d8df8c01..877c0f782f052 100644 --- a/app/code/Magento/Customer/Model/Plugin/AllowedCountriesAddressFilter.php +++ b/app/code/Magento/Customer/Model/Plugin/AllowedCountriesAddressFilter.php @@ -11,9 +11,6 @@ use Magento\Store\Model\ScopeInterface; use Magento\Directory\Model\AllowedCountries; -/** - * Class AllowedCountriesAddressFilter - */ class AllowedCountriesAddressFilter { /** @@ -42,10 +39,8 @@ public function __construct( * Filter customer saved addresses by allowed countries of their store. * * @param \Magento\Customer\Model\ResourceModel\Address\Collection $subject - * @param \Magento\Customer\Model\Customer|array $customer - * @return $this */ - public function beforeSetCustomerFilter(Collection $subject, $customer) + public function beforeSetCustomerFilter(Collection $subject) { $storeId = $this->addressBlock->getStoreId() ?? null; if ($storeId) { diff --git a/app/etc/di.xml b/app/etc/di.xml index 078fe71913fd7..2b741fedd6e1a 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -753,7 +753,7 @@ - Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink + Magento\Framework\App\View\Asset\MaterializationStrategy\Copy Magento\Framework\App\View\Asset\MaterializationStrategy\Copy From 5502fafd5ecca86f28dfe99b9eb3cf66f4d8f38d Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Mon, 13 Sep 2021 18:45:55 +0530 Subject: [PATCH 13/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings --- app/etc/di.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/etc/di.xml b/app/etc/di.xml index 2b741fedd6e1a..078fe71913fd7 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -753,7 +753,7 @@ - Magento\Framework\App\View\Asset\MaterializationStrategy\Copy + Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink Magento\Framework\App\View\Asset\MaterializationStrategy\Copy From 3b9f226584521f514a09f5ac0086bf65a2525732 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Mon, 13 Sep 2021 18:47:26 +0530 Subject: [PATCH 14/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings --- app/code/Magento/Customer/etc/di.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/code/Magento/Customer/etc/di.xml b/app/code/Magento/Customer/etc/di.xml index 5e07a7aeb1f62..1388c7730ffa8 100644 --- a/app/code/Magento/Customer/etc/di.xml +++ b/app/code/Magento/Customer/etc/di.xml @@ -243,6 +243,7 @@ EavVersionControlSnapshot + @@ -366,9 +367,6 @@ - - - From 48ddccc3c32f150147b435efe24baad4510c8afe Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Tue, 14 Sep 2021 14:54:59 +0530 Subject: [PATCH 15/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings --- .../Plugin/AllowedCountriesAddressFilter.php | 55 ---------------- .../Address/StoreAddressCollection.php | 65 +++++++++++++++++++ app/code/Magento/Customer/etc/di.xml | 1 - .../layout/sales_order_create_index.xml | 4 +- ...rder_create_load_block_billing_address.xml | 2 +- .../sales_order_create_load_block_data.xml | 4 +- ...der_create_load_block_shipping_address.xml | 2 +- 7 files changed, 71 insertions(+), 62 deletions(-) delete mode 100644 app/code/Magento/Customer/Model/Plugin/AllowedCountriesAddressFilter.php create mode 100644 app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php diff --git a/app/code/Magento/Customer/Model/Plugin/AllowedCountriesAddressFilter.php b/app/code/Magento/Customer/Model/Plugin/AllowedCountriesAddressFilter.php deleted file mode 100644 index 877c0f782f052..0000000000000 --- a/app/code/Magento/Customer/Model/Plugin/AllowedCountriesAddressFilter.php +++ /dev/null @@ -1,55 +0,0 @@ -allowedCountryReader = $allowedCountryReader; - $this->addressBlock = $addressBlock; - } - - /** - * Filter customer saved addresses by allowed countries of their store. - * - * @param \Magento\Customer\Model\ResourceModel\Address\Collection $subject - */ - public function beforeSetCustomerFilter(Collection $subject) - { - $storeId = $this->addressBlock->getStoreId() ?? null; - if ($storeId) { - $allowedCountries = $this->allowedCountryReader->getAllowedCountries( - ScopeInterface::SCOPE_STORE, - $storeId - ); - - $subject->addAttributeToFilter('country_id', ['in' => $allowedCountries]); - } - } -} diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php new file mode 100644 index 0000000000000..73517a0335f3c --- /dev/null +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php @@ -0,0 +1,65 @@ +addressBlock = ObjectManager::getInstance()->get(AddressBlock::class); + $this->allowedCountryReader = ObjectManager::getInstance()->get(AllowedCountries::class); + $this->request = ObjectManager::getInstance()->get(RequestInterface::class); + } + + /** + * Set customer filter + * + * @param \Magento\Customer\Model\Customer|array $customer + * @return $this + */ + public function setCustomerFilter($customer) + { + parent::setCustomerFilter($customer); + + $storeId = $this->addressBlock->getStoreId() ?? null; + //echo $storeId;die; + if ($storeId) { + $allowedCountries = $this->allowedCountryReader->getAllowedCountries( + ScopeInterface::SCOPE_STORE, + $storeId + ); + $this->addAttributeToFilter('country_id', ['in' => $allowedCountries]); + } + return $this; + } +} diff --git a/app/code/Magento/Customer/etc/di.xml b/app/code/Magento/Customer/etc/di.xml index 1388c7730ffa8..156986b7b4a3c 100644 --- a/app/code/Magento/Customer/etc/di.xml +++ b/app/code/Magento/Customer/etc/di.xml @@ -243,7 +243,6 @@ EavVersionControlSnapshot - diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml index 3832476ff6972..c8f88ea1e4a81 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml @@ -48,13 +48,13 @@ Magento\Sales\ViewModel\Customer\AddressFormatter - Magento\Customer\Model\ResourceModel\Address\Collection + Magento\Customer\Model\ResourceModel\Address\StoreAddressCollection Magento\Sales\ViewModel\Customer\AddressFormatter - Magento\Customer\Model\ResourceModel\Address\Collection + Magento\Customer\Model\ResourceModel\Address\StoreAddressCollection diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_billing_address.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_billing_address.xml index 91148d86055fc..cc417882cee24 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_billing_address.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_billing_address.xml @@ -11,7 +11,7 @@ Magento\Sales\ViewModel\Customer\AddressFormatter - Magento\Customer\Model\ResourceModel\Address\Collection + Magento\Customer\Model\ResourceModel\Address\StoreAddressCollection Magento\Sales\ViewModel\Customer\Address\Billing\AddressDataProvider diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_data.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_data.xml index 54348ce961c56..fe5add54f9474 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_data.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_data.xml @@ -23,13 +23,13 @@ Magento\Sales\ViewModel\Customer\AddressFormatter - Magento\Customer\Model\ResourceModel\Address\Collection + Magento\Customer\Model\ResourceModel\Address\StoreAddressCollection Magento\Sales\ViewModel\Customer\AddressFormatter - Magento\Customer\Model\ResourceModel\Address\Collection + Magento\Customer\Model\ResourceModel\Address\StoreAddressCollection diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_shipping_address.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_shipping_address.xml index 559f56dcb845b..766bea6f4278a 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_shipping_address.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_shipping_address.xml @@ -11,7 +11,7 @@ Magento\Sales\ViewModel\Customer\AddressFormatter - Magento\Customer\Model\ResourceModel\Address\Collection + Magento\Customer\Model\ResourceModel\Address\StoreAddressCollection From cc25581f7f4d746f7a6e2af011bf7a344762285c Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Tue, 14 Sep 2021 18:18:14 +0530 Subject: [PATCH 16/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings --- .../ResourceModel/Address/StoreAddressCollection.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php index 73517a0335f3c..b70a33208769f 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php @@ -8,7 +8,6 @@ use Magento\Framework\App\ObjectManager; use Magento\Sales\Block\Adminhtml\Order\Create\Form\Address as AddressBlock; use Magento\Directory\Model\AllowedCountries; -use Magento\Framework\App\RequestInterface; use Magento\Store\Model\ScopeInterface; class StoreAddressCollection extends \Magento\Customer\Model\ResourceModel\Address\Collection @@ -23,11 +22,6 @@ class StoreAddressCollection extends \Magento\Customer\Model\ResourceModel\Addre */ private $allowedCountryReader; - /** - * @var RequestInterface - */ - private $request; - /** * Resource initialization * @@ -36,9 +30,9 @@ class StoreAddressCollection extends \Magento\Customer\Model\ResourceModel\Addre protected function _construct() { parent::_construct(); + $this->addressBlock = ObjectManager::getInstance()->get(AddressBlock::class); $this->allowedCountryReader = ObjectManager::getInstance()->get(AllowedCountries::class); - $this->request = ObjectManager::getInstance()->get(RequestInterface::class); } /** @@ -52,7 +46,6 @@ public function setCustomerFilter($customer) parent::setCustomerFilter($customer); $storeId = $this->addressBlock->getStoreId() ?? null; - //echo $storeId;die; if ($storeId) { $allowedCountries = $this->allowedCountryReader->getAllowedCountries( ScopeInterface::SCOPE_STORE, From 11eb4e962d0e6a93d265d1ba6d46bb5c8f3a3e8a Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Wed, 15 Sep 2021 17:23:10 +0530 Subject: [PATCH 17/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings --- .../Attribute/Source/CountryWithWebsites.php | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php b/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php index 1ca1c5622803f..3ac142ecf16cf 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php @@ -19,6 +19,7 @@ use Magento\Eav\Model\Entity\Attribute\Source\Table; use Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory as OptionCollectionFactory; use Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory as AttrubuteOptionFactory; +use Magento\Framework\App\ObjectManager; use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; @@ -52,6 +53,16 @@ class CountryWithWebsites extends Table */ private $shareConfig; + /** + * @var \Magento\Framework\App\Request\Http + */ + private $request; + + /** + * @var \Magento\Customer\Api\CustomerRepositoryInterface + */ + private $customerRepository; + /** * @param OptionCollectionFactory $attrOptionCollectionFactory * @param AttrubuteOptionFactory $attrOptionFactory @@ -59,6 +70,8 @@ class CountryWithWebsites extends Table * @param AllowedCountries $allowedCountriesReader * @param StoreManagerInterface $storeManager * @param Share $shareConfig + * @param \Magento\Framework\App\Request\Http|null $request + * @param \Magento\Customer\Api\CustomerRepositoryInterface|null $customerRepository */ public function __construct( OptionCollectionFactory $attrOptionCollectionFactory, @@ -66,12 +79,18 @@ public function __construct( CountryCollectionFactory $countriesFactory, AllowedCountries $allowedCountriesReader, StoreManagerInterface $storeManager, - CustomerShareConfig $shareConfig + CustomerShareConfig $shareConfig, + ?\Magento\Framework\App\Request\Http $request = null, + ?\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository = null ) { $this->countriesFactory = $countriesFactory; $this->allowedCountriesReader = $allowedCountriesReader; $this->storeManager = $storeManager; $this->shareConfig = $shareConfig; + $this->request = $request + ?? ObjectManager::getInstance()->get(\Magento\Framework\App\Request\Http::class); + $this->customerRepository = $customerRepository + ?? ObjectManager::getInstance()->get(\Magento\Customer\Api\CustomerRepositoryInterface::class); parent::__construct($attrOptionCollectionFactory, $attrOptionFactory); } @@ -98,7 +117,14 @@ public function getAllOptions($withEmpty = true, $defaultValues = false) $allowedCountries = array_unique(array_merge([], ...$allowedCountries)); } else { - $allowedCountries = $this->allowedCountriesReader->getAllowedCountries(); + $storeId = null; + $customerId = $this->request->getParam('parent_id') ?? null; + if ($customerId) { + $customer = $this->customerRepository->getById($customerId); + $storeId = $customer->getStoreId(); + } + + $allowedCountries = $this->allowedCountriesReader->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE, $storeId); } $this->options = $this->createCountriesCollection() From ae7cac54d5e0ca232da1b48d3aa20fa18ae1d1dc Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Wed, 15 Sep 2021 18:31:50 +0530 Subject: [PATCH 18/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings --- .../Address/Attribute/Source/CountryWithWebsites.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php b/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php index 3ac142ecf16cf..0522c042cbd77 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php @@ -117,6 +117,7 @@ public function getAllOptions($withEmpty = true, $defaultValues = false) $allowedCountries = array_unique(array_merge([], ...$allowedCountries)); } else { + // Address can be added only for the allowed country list. $storeId = null; $customerId = $this->request->getParam('parent_id') ?? null; if ($customerId) { @@ -124,7 +125,10 @@ public function getAllOptions($withEmpty = true, $defaultValues = false) $storeId = $customer->getStoreId(); } - $allowedCountries = $this->allowedCountriesReader->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE, $storeId); + $allowedCountries = $this->allowedCountriesReader->getAllowedCountries( + ScopeInterface::SCOPE_WEBSITE, + $storeId + ); } $this->options = $this->createCountriesCollection() From dcc4f97e5c8c677a788d55a0c628876d0c530de3 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Wed, 22 Sep 2021 15:16:37 +0530 Subject: [PATCH 19/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings --- .../Address/StoreAddressCollection.php | 63 +++++++++++++++++-- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php index b70a33208769f..4f1bc9f01bdeb 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php @@ -5,13 +5,19 @@ */ namespace Magento\Customer\Model\ResourceModel\Address; -use Magento\Framework\App\ObjectManager; -use Magento\Sales\Block\Adminhtml\Order\Create\Form\Address as AddressBlock; use Magento\Directory\Model\AllowedCountries; +use Magento\Sales\Block\Adminhtml\Order\Create\Form\Address as AddressBlock; use Magento\Store\Model\ScopeInterface; -class StoreAddressCollection extends \Magento\Customer\Model\ResourceModel\Address\Collection +class StoreAddressCollection extends Collection { + /** + * Object Manager instance + * + * @var \Magento\Framework\ObjectManagerInterface + */ + protected $_objectManager; + /** * @var AddressBlock */ @@ -22,6 +28,51 @@ class StoreAddressCollection extends \Magento\Customer\Model\ResourceModel\Addre */ private $allowedCountryReader; + /** + * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory + * @param \Psr\Log\LoggerInterface $logger + * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy + * @param \Magento\Framework\Event\ManagerInterface $eventManager + * @param \Magento\Eav\Model\Config $eavConfig + * @param \Magento\Framework\App\ResourceConnection $resource + * @param \Magento\Eav\Model\EntityFactory $eavEntityFactory + * @param \Magento\Eav\Model\ResourceModel\Helper $resourceHelper + * @param \Magento\Framework\Validator\UniversalFactory $universalFactory + * @param \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot + * @param \Magento\Framework\ObjectManagerInterface $objectManager + * @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection + */ + public function __construct( + \Magento\Framework\Data\Collection\EntityFactory $entityFactory, + \Psr\Log\LoggerInterface $logger, + \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, + \Magento\Framework\Event\ManagerInterface $eventManager, + \Magento\Eav\Model\Config $eavConfig, + \Magento\Framework\App\ResourceConnection $resource, + \Magento\Eav\Model\EntityFactory $eavEntityFactory, + \Magento\Eav\Model\ResourceModel\Helper $resourceHelper, + \Magento\Framework\Validator\UniversalFactory $universalFactory, + \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot, + \Magento\Framework\ObjectManagerInterface $objectManager, + \Magento\Framework\DB\Adapter\AdapterInterface $connection = null + ) { + $this->_objectManager = $objectManager; + + parent::__construct( + $entityFactory, + $logger, + $fetchStrategy, + $eventManager, + $eavConfig, + $resource, + $eavEntityFactory, + $resourceHelper, + $universalFactory, + $entitySnapshot, + $connection + ); + } + /** * Resource initialization * @@ -31,12 +82,12 @@ protected function _construct() { parent::_construct(); - $this->addressBlock = ObjectManager::getInstance()->get(AddressBlock::class); - $this->allowedCountryReader = ObjectManager::getInstance()->get(AllowedCountries::class); + $this->addressBlock = $this->_objectManager->create(AddressBlock::class); + $this->allowedCountryReader = $this->_objectManager->create(AllowedCountries::class); } /** - * Set customer filter + * Set allowed country filter for customer's addresses * * @param \Magento\Customer\Model\Customer|array $customer * @return $this From 286eeffa7169a394a8deece6257f4575d37b9391 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Wed, 22 Sep 2021 16:43:38 +0530 Subject: [PATCH 20/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings --- .../Model/ResourceModel/Address/StoreAddressCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php index 4f1bc9f01bdeb..a96027dd3a3df 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php @@ -16,7 +16,7 @@ class StoreAddressCollection extends Collection * * @var \Magento\Framework\ObjectManagerInterface */ - protected $_objectManager; + private $_objectManager; /** * @var AddressBlock From 30aef4da348684cde75ab313389854f84b635d2f Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Wed, 22 Sep 2021 17:50:36 +0530 Subject: [PATCH 21/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings --- .../Model/ResourceModel/Address/StoreAddressCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php index a96027dd3a3df..104affbc70857 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php @@ -78,7 +78,7 @@ public function __construct( * * @return void */ - protected function _construct() + public function _construct() { parent::_construct(); From 46ae124f2df8c9962cf7a7bcafff48b9c09f12ce Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Wed, 22 Sep 2021 18:45:24 +0530 Subject: [PATCH 22/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage implemented --- .../CustomerAddressDataProviderTest.php | 438 ++++++++++++++++++ 1 file changed, 438 insertions(+) create mode 100644 app/code/Magento/Customer/Test/Unit/Model/Address/CustomerAddressDataProviderTest.php diff --git a/app/code/Magento/Customer/Test/Unit/Model/Address/CustomerAddressDataProviderTest.php b/app/code/Magento/Customer/Test/Unit/Model/Address/CustomerAddressDataProviderTest.php new file mode 100644 index 0000000000000..40e7280558be2 --- /dev/null +++ b/app/code/Magento/Customer/Test/Unit/Model/Address/CustomerAddressDataProviderTest.php @@ -0,0 +1,438 @@ +objectManager = new ObjectManager($this); + + $this->customerMock = $this->getMockForAbstractClass(CustomerInterface::class); + $this->addressMock = $this->getMockForAbstractClass(AddressInterface::class); + ############## + $this->addressCollectionFactory = $this->getMockBuilder(CollectionFactory::class) + ->disableOriginalConstructor() + ->onlyMethods(['create']) + ->getMock(); + $this->collection = $this->getMockBuilder(AddressCollection::class) + ->disableOriginalConstructor() + ->getMock(); + $this->customerRepository = $this->getMockForAbstractClass(CustomerRepositoryInterface::class); + /*$this->addressCollectionFactory->expects($this->once()) + ->method('create') + ->willReturn($this->collection);*/ + //$this->customer = $this->getMockForAbstractClass(CustomerInterface::class); + $this->address = $this->getMockBuilder(AddressModel::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->customerFactory = $this->getMockBuilder(CustomerInterfaceFactory::class) + ->onlyMethods(['create']) + ->disableOriginalConstructor() + ->getMock(); + $this->addressFactory = $this->getMockBuilder(AddressInterfaceFactory::class) + ->onlyMethods(['create']) + ->disableOriginalConstructor() + ->getMock(); + + /*$this->address = $this->getMockBuilder(AddressModel::class) + ->disableOriginalConstructor() + ->getMock();*/ + $this->storeManagerMock = $this->getMockForAbstractClass(StoreManagerInterface::class); + + ############ + $this->allowedCountriesMock = $this->getMockBuilder(AllowedCountries::class) + ->disableOriginalConstructor() + ->getMock(); + $this->shareConfigMock = $this->getMockBuilder(Share::class) + ->disableOriginalConstructor() + ->getMock(); + $this->customerAddressDataFormatter = $this->getMockBuilder(CustomerAddressDataFormatter::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->customerAddressDataProvider = new CustomerAddressDataProvider( + $this->customerAddressDataFormatter, + $this->shareConfigMock, + $this->allowedCountriesMock + ); + + } + + public function testV1() + { + + $this->customerMock->expects($this->once()) + ->method('getAddresses') + ->willReturnSelf(); + $this->customerAddressDataFormatter->expects($this->once()) + ->method('prepareAddress') + ->willReturnSelf(); + + $result = $this->customerAddressDataProvider->getAddressDataByCustomer($this->customerMock); + $this->assertEmpty($result); + } + + + + + public function testABC() + { + $addressData = [ + 'id' => 1, + 'parent_id' => 1, + 'firstname' => 'F', + 'lastname' => 'Doe', + 'street' => "Street 1\nStreet 2", + 'city' => 'Austin', + 'postcode' => 07201, + 'region_id' => 1, + 'company' => 'Magento', + 'fax' => '222-22-22', + ]; + $customerData = [ + 'firstname' => 'Jhon', + 'lastname' => 'Doe', + 'email' => 'customer@email.com', + ]; + + $customerFactory = $this->createPartialMock(CustomerFactory::class, ['create']); + $customerFactory->expects($this->any())->method('create')->will($this->returnValue($this->customerMock)); + $this->customerMock->setData($customerData); + $addressMock = $this->getMockBuilder(Address::class) + ->onlyMethods(['getId']) + ->disableOriginalConstructor() + ->getMock(); + $addressMock->setData($addressData); + $this->customerMock->addAddress($addressMock); + } + + + + + public function testGetAddressDataByCustomer() + { + $addressMock = $this->getMockBuilder(AddressInterface::class) + ->setMethods( + [ + 'getId', + 'getCountryId', + 'setData', + 'getData' + ] + ) + ->getMockForAbstractClass(); + + $expectedData = [ + '1' => [ + 'parent_id' => '1', + 'default_billing' => '1', + 'default_shipping' => '1', + 'firstname' => 'John', + 'lastname' => 'Doe', + 'street' => [ + '42000 Ave W 55 Cedar City', + 'Apt. 33' + ] + ] + ]; + + $this->addressMock->expects($this->once()) + ->method('getId') + ->willReturn('1'); + + $this->customerAddressDataFormatter->expects($this->once()) + ->method('prepareAddress') + ->willReturnSelf(); + + $this->customerMock->expects($this->any()) + ->method('getAddresses') + ->willReturn($expectedData); + + $this->addressMock->expects($this->any())->method('getCountryId')->willReturn('US'); + + $result = $this->customerAddressDataProvider->getAddressDataByCustomer($this->customerMock); + $this->assertEmpty($result); + } + + + + + public function testCreateNewCustomerWithAddress(): void + { + $availableCountry = 'BD'; + $address = $this->addressFactory->create(); + $address->setCountryId($availableCountry) + ->setPostcode('75477') + ->setRegionId(1) + ->setStreet(['Green str, 67']) + ->setTelephone('3468676') + ->setCity('CityM') + ->setFirstname('John') + ->setLastname('Smith') + ->setIsDefaultShipping(true) + ->setIsDefaultBilling(true); + $customerEntity = $this->customerFactory->create(); + $customerEntity->setEmail('test@example.com') + ->setFirstname('John') + ->setLastname('Smith') + ->setStoreId(1); + $customerEntity->setAddresses([$address]); + $this->customer = $this->accountManagement->createAccount($customerEntity); + $this->assertCount(1, $this->customer->getAddresses(), 'The available address wasn\'t saved.'); + $this->assertSame( + $availableCountry, + $this->customer->getAddresses()[0]->getCountryId(), + 'The address was saved with disallowed country.' + ); + } + + + + + public function testGetAddressDataByCustomer2() + { + $allowedCountries = ['IN', 'FR']; + $expectedResult = [ + 'id' => 1, + 'parent_id' => 1, + 'firstname' => 'John', + 'lastname' => 'Doe', + 'street' => "Street 1\nStreet 2", + 'city' => 'Austin', + 'postcode' => 07201, + 'region_id' => 1, + 'company' => 'Magento', + 'fax' => '222-22-22', + ]; + $expectedResultWithAllowedCountry = array_merge( + $expectedResult, + [ + 'country_id' => 'IN', + ] + ); + $expectedResultWithoutAllowedCountry = array_merge( + $expectedResult, + [ + 'country_id' => 'US', + ] + ); + + $addressMock = $this->getMockBuilder(Address::class) + ->onlyMethods(['getId']) + ->disableOriginalConstructor() + ->getMock(); + $addressMock->setData( + [ + 'entity_id' => 1, + 'attribute_set_id' => 2, + 'telephone' => 3468676, + 'postcode' => 75477, + 'country_id' => 'US', + 'city' => 'CityM', + 'company' => 'CompanyName', + 'street' => 'Green str, 67', + 'lastname' => 'Smith', + 'firstname' => 'John', + 'parent_id' => 1, + 'region_id' => 1, + ] + ); + + $customerMock1 = $this->getMockForAbstractClass(CustomerInterface::class); + $customerMock2 = $this->getMockForAbstractClass(CustomerInterface::class); + $customerMock2->setId(1); + $customerMock2->setAddresses($addressMock); + + $customerMock1->expects($this->atLeastOnce()) + ->method('getAddresses') + ->willReturn($expectedResultWithAllowedCountry); + $customerMock2->expects($this->atLeastOnce()) + ->method('getAddresses') + ->willReturn($expectedResultWithAllowedCountry); + + $result = $this->customerAddressDataProvider->getAddressDataByCustomer($customerMock2); + $this->assertEmpty($result); + //$this->assertEquals($expectedResultWithAllowedCountry, $result); + + /*$customersIds = [10, 11, 12]; + $customerMock = $this->getMockBuilder(CustomerInterface::class) + ->setMethods(['setData']) + ->disableOriginalConstructor() + ->getMockForAbstractClass();*/ + + /*$customerData->expects($this->once()) + ->method('setId') + ->with(1) + ->willReturnSelf(); + + $this->customerFactory->expects($this->once()) + ->method('create') + ->willReturn($customerData);*/ + + /*$customerDataArray = ['entity_id' => 1]; + $customerModel->expects($this->once()) + ->method('getData') + ->willReturn($customerDataArray);*/ + + + + + + /*$customerDataObject = $this->getMockForAbstractClass(CustomerInterface::class); + $customerDataFactory = $this->getMockBuilder(CustomerInterfaceFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $customerDataFactory->expects($this->atLeastOnce())->method('create')->willReturn($customerDataObject);*/ + + //$customerMock = $this->getMockForAbstractClass(CustomerInterfa + $regionId = 1; + /*$this->address->setData('id', 1); + $this->address->setData('parent_id', 1); + $this->address->setData('firstname', 'John'); + $this->address->setData('lastname', 'Doe'); + $this->address->setData('street', "Street 1\nStreet 2"); + $this->address->setData('city', 'Austin'); + $this->address->setData('postcode', 07201); + $this->address->setData('region_id', 1); + $this->address->setData('company', 'Magento'); + $this->address->setData('fax', '222-22-22'); + $this->address->setData('country_id', 1);*/ + /*$this->address->setData($expectedResultWithAllowedCountry); + var_dump($this->address->getData()); + $this->customer->expects($this->any())->method('getAddresses')->willReturn($this->address); + + + + $result = $this->customerAddressDataProvider->getAddressDataByCustomer($this->customer); + $this->assertEmpty($result);*/ + //$this->assertEquals($expectedResultWithAllowedCountry, $result); + + /*$customer1 = $this->getMockForAbstractClass(CustomerInterface::class); + $customer2 = $this->getMockForAbstractClass(CustomerInterface::class); + + $customer1->expects($this->atLeastOnce()) + ->method('getAddresses') + ->willReturnSelf();*/ + + /*$address = $customer1->expects($this->atLeastOnce()) + ->method('getAddresses');*/ + + /* $customer1->expects($this->atLeastOnce()) + ->method('getWebsiteId') + ->willReturn(1); + $customer2->expects($this->atLeastOnce()) + ->method('getWebsiteId') + ->willReturn(2);*/ + + + /*$this->allowedCountriesMock->expects($this->exactly(2)) + ->method('getAllowedCountries') + ->withConsecutive( + ['website', 1], + ['website', 2] + ) + ->willReturnMap([ + ['website', 1, ['AM' => 'AM']], + ['website', 2, ['AM' => 'AM', 'DZ' => 'DZ']] + ]);*/ + + /*$result = $this->customerAddressDataProvider->getAddressDataByCustomer($customer1); + var_dump($result);*/ + + } +} From d294eecd05919814271c51c21d45b014df0436e3 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Wed, 22 Sep 2021 18:46:31 +0530 Subject: [PATCH 23/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage implemented --- .../Address/StoreAddressCollectionTest.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php new file mode 100644 index 0000000000000..c246f752ec7b0 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php @@ -0,0 +1,40 @@ +create( + \Magento\Customer\Model\ResourceModel\Address\StoreAddressCollection::class + ); + $select = $collection->getSelect(); + $this->assertSame($collection, $collection->setCustomerFilter([1, 2])); + $customer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + \Magento\Customer\Model\Customer::class + ); + $collection->setCustomerFilter($customer); + $customer->setId(3); + $collection->setCustomerFilter($customer); + $allowedCountriesObj = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + \Magento\Directory\Model\AllowedCountries::class + ); + $storeId = $customer->getStoreId(); + $allowedCountries = $allowedCountriesObj->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId); + $strAllowedCountries = implode("%S, %S", $allowedCountries); + $this->assertStringMatchesFormat( + '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)%SAND%S(%Sparent_id%S = %S3%S)%SAND%S(%Scountry_id%S IN(%S'.$strAllowedCountries.'%S))%A', + (string)$select + ); + } +} From a0b30e4f4054ede960c30910d3a428701c91f6d5 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Wed, 22 Sep 2021 18:50:49 +0530 Subject: [PATCH 24/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage implemented --- .../CustomerAddressDataProviderTest.php | 438 ------------------ 1 file changed, 438 deletions(-) delete mode 100644 app/code/Magento/Customer/Test/Unit/Model/Address/CustomerAddressDataProviderTest.php diff --git a/app/code/Magento/Customer/Test/Unit/Model/Address/CustomerAddressDataProviderTest.php b/app/code/Magento/Customer/Test/Unit/Model/Address/CustomerAddressDataProviderTest.php deleted file mode 100644 index 40e7280558be2..0000000000000 --- a/app/code/Magento/Customer/Test/Unit/Model/Address/CustomerAddressDataProviderTest.php +++ /dev/null @@ -1,438 +0,0 @@ -objectManager = new ObjectManager($this); - - $this->customerMock = $this->getMockForAbstractClass(CustomerInterface::class); - $this->addressMock = $this->getMockForAbstractClass(AddressInterface::class); - ############## - $this->addressCollectionFactory = $this->getMockBuilder(CollectionFactory::class) - ->disableOriginalConstructor() - ->onlyMethods(['create']) - ->getMock(); - $this->collection = $this->getMockBuilder(AddressCollection::class) - ->disableOriginalConstructor() - ->getMock(); - $this->customerRepository = $this->getMockForAbstractClass(CustomerRepositoryInterface::class); - /*$this->addressCollectionFactory->expects($this->once()) - ->method('create') - ->willReturn($this->collection);*/ - //$this->customer = $this->getMockForAbstractClass(CustomerInterface::class); - $this->address = $this->getMockBuilder(AddressModel::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->customerFactory = $this->getMockBuilder(CustomerInterfaceFactory::class) - ->onlyMethods(['create']) - ->disableOriginalConstructor() - ->getMock(); - $this->addressFactory = $this->getMockBuilder(AddressInterfaceFactory::class) - ->onlyMethods(['create']) - ->disableOriginalConstructor() - ->getMock(); - - /*$this->address = $this->getMockBuilder(AddressModel::class) - ->disableOriginalConstructor() - ->getMock();*/ - $this->storeManagerMock = $this->getMockForAbstractClass(StoreManagerInterface::class); - - ############ - $this->allowedCountriesMock = $this->getMockBuilder(AllowedCountries::class) - ->disableOriginalConstructor() - ->getMock(); - $this->shareConfigMock = $this->getMockBuilder(Share::class) - ->disableOriginalConstructor() - ->getMock(); - $this->customerAddressDataFormatter = $this->getMockBuilder(CustomerAddressDataFormatter::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->customerAddressDataProvider = new CustomerAddressDataProvider( - $this->customerAddressDataFormatter, - $this->shareConfigMock, - $this->allowedCountriesMock - ); - - } - - public function testV1() - { - - $this->customerMock->expects($this->once()) - ->method('getAddresses') - ->willReturnSelf(); - $this->customerAddressDataFormatter->expects($this->once()) - ->method('prepareAddress') - ->willReturnSelf(); - - $result = $this->customerAddressDataProvider->getAddressDataByCustomer($this->customerMock); - $this->assertEmpty($result); - } - - - - - public function testABC() - { - $addressData = [ - 'id' => 1, - 'parent_id' => 1, - 'firstname' => 'F', - 'lastname' => 'Doe', - 'street' => "Street 1\nStreet 2", - 'city' => 'Austin', - 'postcode' => 07201, - 'region_id' => 1, - 'company' => 'Magento', - 'fax' => '222-22-22', - ]; - $customerData = [ - 'firstname' => 'Jhon', - 'lastname' => 'Doe', - 'email' => 'customer@email.com', - ]; - - $customerFactory = $this->createPartialMock(CustomerFactory::class, ['create']); - $customerFactory->expects($this->any())->method('create')->will($this->returnValue($this->customerMock)); - $this->customerMock->setData($customerData); - $addressMock = $this->getMockBuilder(Address::class) - ->onlyMethods(['getId']) - ->disableOriginalConstructor() - ->getMock(); - $addressMock->setData($addressData); - $this->customerMock->addAddress($addressMock); - } - - - - - public function testGetAddressDataByCustomer() - { - $addressMock = $this->getMockBuilder(AddressInterface::class) - ->setMethods( - [ - 'getId', - 'getCountryId', - 'setData', - 'getData' - ] - ) - ->getMockForAbstractClass(); - - $expectedData = [ - '1' => [ - 'parent_id' => '1', - 'default_billing' => '1', - 'default_shipping' => '1', - 'firstname' => 'John', - 'lastname' => 'Doe', - 'street' => [ - '42000 Ave W 55 Cedar City', - 'Apt. 33' - ] - ] - ]; - - $this->addressMock->expects($this->once()) - ->method('getId') - ->willReturn('1'); - - $this->customerAddressDataFormatter->expects($this->once()) - ->method('prepareAddress') - ->willReturnSelf(); - - $this->customerMock->expects($this->any()) - ->method('getAddresses') - ->willReturn($expectedData); - - $this->addressMock->expects($this->any())->method('getCountryId')->willReturn('US'); - - $result = $this->customerAddressDataProvider->getAddressDataByCustomer($this->customerMock); - $this->assertEmpty($result); - } - - - - - public function testCreateNewCustomerWithAddress(): void - { - $availableCountry = 'BD'; - $address = $this->addressFactory->create(); - $address->setCountryId($availableCountry) - ->setPostcode('75477') - ->setRegionId(1) - ->setStreet(['Green str, 67']) - ->setTelephone('3468676') - ->setCity('CityM') - ->setFirstname('John') - ->setLastname('Smith') - ->setIsDefaultShipping(true) - ->setIsDefaultBilling(true); - $customerEntity = $this->customerFactory->create(); - $customerEntity->setEmail('test@example.com') - ->setFirstname('John') - ->setLastname('Smith') - ->setStoreId(1); - $customerEntity->setAddresses([$address]); - $this->customer = $this->accountManagement->createAccount($customerEntity); - $this->assertCount(1, $this->customer->getAddresses(), 'The available address wasn\'t saved.'); - $this->assertSame( - $availableCountry, - $this->customer->getAddresses()[0]->getCountryId(), - 'The address was saved with disallowed country.' - ); - } - - - - - public function testGetAddressDataByCustomer2() - { - $allowedCountries = ['IN', 'FR']; - $expectedResult = [ - 'id' => 1, - 'parent_id' => 1, - 'firstname' => 'John', - 'lastname' => 'Doe', - 'street' => "Street 1\nStreet 2", - 'city' => 'Austin', - 'postcode' => 07201, - 'region_id' => 1, - 'company' => 'Magento', - 'fax' => '222-22-22', - ]; - $expectedResultWithAllowedCountry = array_merge( - $expectedResult, - [ - 'country_id' => 'IN', - ] - ); - $expectedResultWithoutAllowedCountry = array_merge( - $expectedResult, - [ - 'country_id' => 'US', - ] - ); - - $addressMock = $this->getMockBuilder(Address::class) - ->onlyMethods(['getId']) - ->disableOriginalConstructor() - ->getMock(); - $addressMock->setData( - [ - 'entity_id' => 1, - 'attribute_set_id' => 2, - 'telephone' => 3468676, - 'postcode' => 75477, - 'country_id' => 'US', - 'city' => 'CityM', - 'company' => 'CompanyName', - 'street' => 'Green str, 67', - 'lastname' => 'Smith', - 'firstname' => 'John', - 'parent_id' => 1, - 'region_id' => 1, - ] - ); - - $customerMock1 = $this->getMockForAbstractClass(CustomerInterface::class); - $customerMock2 = $this->getMockForAbstractClass(CustomerInterface::class); - $customerMock2->setId(1); - $customerMock2->setAddresses($addressMock); - - $customerMock1->expects($this->atLeastOnce()) - ->method('getAddresses') - ->willReturn($expectedResultWithAllowedCountry); - $customerMock2->expects($this->atLeastOnce()) - ->method('getAddresses') - ->willReturn($expectedResultWithAllowedCountry); - - $result = $this->customerAddressDataProvider->getAddressDataByCustomer($customerMock2); - $this->assertEmpty($result); - //$this->assertEquals($expectedResultWithAllowedCountry, $result); - - /*$customersIds = [10, 11, 12]; - $customerMock = $this->getMockBuilder(CustomerInterface::class) - ->setMethods(['setData']) - ->disableOriginalConstructor() - ->getMockForAbstractClass();*/ - - /*$customerData->expects($this->once()) - ->method('setId') - ->with(1) - ->willReturnSelf(); - - $this->customerFactory->expects($this->once()) - ->method('create') - ->willReturn($customerData);*/ - - /*$customerDataArray = ['entity_id' => 1]; - $customerModel->expects($this->once()) - ->method('getData') - ->willReturn($customerDataArray);*/ - - - - - - /*$customerDataObject = $this->getMockForAbstractClass(CustomerInterface::class); - $customerDataFactory = $this->getMockBuilder(CustomerInterfaceFactory::class) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - $customerDataFactory->expects($this->atLeastOnce())->method('create')->willReturn($customerDataObject);*/ - - //$customerMock = $this->getMockForAbstractClass(CustomerInterfa - $regionId = 1; - /*$this->address->setData('id', 1); - $this->address->setData('parent_id', 1); - $this->address->setData('firstname', 'John'); - $this->address->setData('lastname', 'Doe'); - $this->address->setData('street', "Street 1\nStreet 2"); - $this->address->setData('city', 'Austin'); - $this->address->setData('postcode', 07201); - $this->address->setData('region_id', 1); - $this->address->setData('company', 'Magento'); - $this->address->setData('fax', '222-22-22'); - $this->address->setData('country_id', 1);*/ - /*$this->address->setData($expectedResultWithAllowedCountry); - var_dump($this->address->getData()); - $this->customer->expects($this->any())->method('getAddresses')->willReturn($this->address); - - - - $result = $this->customerAddressDataProvider->getAddressDataByCustomer($this->customer); - $this->assertEmpty($result);*/ - //$this->assertEquals($expectedResultWithAllowedCountry, $result); - - /*$customer1 = $this->getMockForAbstractClass(CustomerInterface::class); - $customer2 = $this->getMockForAbstractClass(CustomerInterface::class); - - $customer1->expects($this->atLeastOnce()) - ->method('getAddresses') - ->willReturnSelf();*/ - - /*$address = $customer1->expects($this->atLeastOnce()) - ->method('getAddresses');*/ - - /* $customer1->expects($this->atLeastOnce()) - ->method('getWebsiteId') - ->willReturn(1); - $customer2->expects($this->atLeastOnce()) - ->method('getWebsiteId') - ->willReturn(2);*/ - - - /*$this->allowedCountriesMock->expects($this->exactly(2)) - ->method('getAllowedCountries') - ->withConsecutive( - ['website', 1], - ['website', 2] - ) - ->willReturnMap([ - ['website', 1, ['AM' => 'AM']], - ['website', 2, ['AM' => 'AM', 'DZ' => 'DZ']] - ]);*/ - - /*$result = $this->customerAddressDataProvider->getAddressDataByCustomer($customer1); - var_dump($result);*/ - - } -} From 629a6b081f6dfd085284a4b56cdde91b7af1cbdd Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Thu, 23 Sep 2021 09:17:46 +0530 Subject: [PATCH 25/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage implemented --- .../ResourceModel/Address/StoreAddressCollection.php | 10 +++++----- .../Address/StoreAddressCollectionTest.php | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php index 104affbc70857..29604f60a96e7 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php @@ -16,7 +16,7 @@ class StoreAddressCollection extends Collection * * @var \Magento\Framework\ObjectManagerInterface */ - private $_objectManager; + private $objectManager; /** * @var AddressBlock @@ -56,7 +56,7 @@ public function __construct( \Magento\Framework\ObjectManagerInterface $objectManager, \Magento\Framework\DB\Adapter\AdapterInterface $connection = null ) { - $this->_objectManager = $objectManager; + $this->objectManager = $objectManager; parent::__construct( $entityFactory, @@ -82,15 +82,15 @@ public function _construct() { parent::_construct(); - $this->addressBlock = $this->_objectManager->create(AddressBlock::class); - $this->allowedCountryReader = $this->_objectManager->create(AllowedCountries::class); + $this->addressBlock = $this->objectManager->create(AddressBlock::class); + $this->allowedCountryReader = $this->objectManager->create(AllowedCountries::class); } /** * Set allowed country filter for customer's addresses * * @param \Magento\Customer\Model\Customer|array $customer - * @return $this + * @return $this|Object */ public function setCustomerFilter($customer) { diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php index c246f752ec7b0..843cd731ef2cc 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php @@ -32,9 +32,8 @@ public function testSetCustomerFilter() $storeId = $customer->getStoreId(); $allowedCountries = $allowedCountriesObj->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId); $strAllowedCountries = implode("%S, %S", $allowedCountries); - $this->assertStringMatchesFormat( - '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)%SAND%S(%Sparent_id%S = %S3%S)%SAND%S(%Scountry_id%S IN(%S'.$strAllowedCountries.'%S))%A', - (string)$select - ); + $format = '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)%SAND%S(%Sparent_id%S = %S3%S)' . + '%SAND%S(%Scountry_id%S IN(%S' . $strAllowedCountries . '%S))%A'; + $this->assertStringMatchesFormat($format, (string)$select); } } From 7712a5ec83c0b1b8763ffe0a65cf55d0bac6da76 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Thu, 23 Sep 2021 11:28:43 +0530 Subject: [PATCH 26/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage implemented --- .../ResourceModel/Address/StoreAddressCollectionTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php index 843cd731ef2cc..99723c70c2d1e 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php @@ -29,11 +29,14 @@ public function testSetCustomerFilter() $allowedCountriesObj = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( \Magento\Directory\Model\AllowedCountries::class ); + $this->assertStringMatchesFormat( + '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)%SAND%S(%Sparent_id%S = %S3%S)%A', + (string)$select + ); $storeId = $customer->getStoreId(); $allowedCountries = $allowedCountriesObj->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId); $strAllowedCountries = implode("%S, %S", $allowedCountries); - $format = '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)%SAND%S(%Sparent_id%S = %S3%S)' . - '%SAND%S(%Scountry_id%S IN(%S' . $strAllowedCountries . '%S))%A'; + $format = '%AWHERE%S(%Scountry_id%S IN(%S' . $strAllowedCountries . '%S))%A'; $this->assertStringMatchesFormat($format, (string)$select); } } From e439d5b8a9149b86df3cad708c530a858f47cece Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Thu, 23 Sep 2021 14:37:36 +0530 Subject: [PATCH 27/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage implemented --- .../Address/StoreAddressCollection.php | 15 ++++++++++++--- .../Address/StoreAddressCollectionTest.php | 4 ---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php index 29604f60a96e7..f2d1657c661d1 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php @@ -6,15 +6,21 @@ namespace Magento\Customer\Model\ResourceModel\Address; use Magento\Directory\Model\AllowedCountries; +use Magento\Framework\ObjectManagerInterface; use Magento\Sales\Block\Adminhtml\Order\Create\Form\Address as AddressBlock; use Magento\Store\Model\ScopeInterface; +/** + * Class Store Address Collection + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class StoreAddressCollection extends Collection { /** * Object Manager instance * - * @var \Magento\Framework\ObjectManagerInterface + * @var ObjectManagerInterface */ private $objectManager; @@ -39,8 +45,10 @@ class StoreAddressCollection extends Collection * @param \Magento\Eav\Model\ResourceModel\Helper $resourceHelper * @param \Magento\Framework\Validator\UniversalFactory $universalFactory * @param \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot - * @param \Magento\Framework\ObjectManagerInterface $objectManager + * @param ObjectManagerInterface $objectManager * @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( \Magento\Framework\Data\Collection\EntityFactory $entityFactory, @@ -53,7 +61,7 @@ public function __construct( \Magento\Eav\Model\ResourceModel\Helper $resourceHelper, \Magento\Framework\Validator\UniversalFactory $universalFactory, \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot, - \Magento\Framework\ObjectManagerInterface $objectManager, + ObjectManagerInterface $objectManager, \Magento\Framework\DB\Adapter\AdapterInterface $connection = null ) { $this->objectManager = $objectManager; @@ -91,6 +99,7 @@ public function _construct() * * @param \Magento\Customer\Model\Customer|array $customer * @return $this|Object + * @throws \Magento\Framework\Exception\LocalizedException */ public function setCustomerFilter($customer) { diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php index 99723c70c2d1e..a6023e1ebf5b4 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php @@ -29,10 +29,6 @@ public function testSetCustomerFilter() $allowedCountriesObj = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( \Magento\Directory\Model\AllowedCountries::class ); - $this->assertStringMatchesFormat( - '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)%SAND%S(%Sparent_id%S = %S3%S)%A', - (string)$select - ); $storeId = $customer->getStoreId(); $allowedCountries = $allowedCountriesObj->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId); $strAllowedCountries = implode("%S, %S", $allowedCountries); From 44a1c698eae4b7c7ee17db29aa91d122474e058e Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Thu, 23 Sep 2021 16:45:42 +0530 Subject: [PATCH 28/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage implemented --- .../Model/ResourceModel/Address/StoreAddressCollection.php | 2 -- .../Model/ResourceModel/Address/StoreAddressCollectionTest.php | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php index f2d1657c661d1..7e1de58a49c91 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php @@ -11,8 +11,6 @@ use Magento\Store\Model\ScopeInterface; /** - * Class Store Address Collection - * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class StoreAddressCollection extends Collection diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php index a6023e1ebf5b4..436e7f84de030 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php @@ -32,7 +32,8 @@ public function testSetCustomerFilter() $storeId = $customer->getStoreId(); $allowedCountries = $allowedCountriesObj->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId); $strAllowedCountries = implode("%S, %S", $allowedCountries); - $format = '%AWHERE%S(%Scountry_id%S IN(%S' . $strAllowedCountries . '%S))%A'; + $format = '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)' . + '%SAND%S(%Sparent_id%S = %S3%S)%SAND%S(%Scountry_id%S IN(%S' . $strAllowedCountries . '%S))%A'; $this->assertStringMatchesFormat($format, (string)$select); } } From 61636fc106fd9f2fc1399efb89e701e87f9d475b Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Fri, 24 Sep 2021 11:29:01 +0530 Subject: [PATCH 29/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage implemented --- .../Address/StoreAddressCollection.php | 30 ++++--------------- .../Address/StoreAddressCollectionTest.php | 4 ++- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php index 7e1de58a49c91..bfde6c5a89c3a 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php @@ -6,7 +6,6 @@ namespace Magento\Customer\Model\ResourceModel\Address; use Magento\Directory\Model\AllowedCountries; -use Magento\Framework\ObjectManagerInterface; use Magento\Sales\Block\Adminhtml\Order\Create\Form\Address as AddressBlock; use Magento\Store\Model\ScopeInterface; @@ -15,13 +14,6 @@ */ class StoreAddressCollection extends Collection { - /** - * Object Manager instance - * - * @var ObjectManagerInterface - */ - private $objectManager; - /** * @var AddressBlock */ @@ -43,7 +35,8 @@ class StoreAddressCollection extends Collection * @param \Magento\Eav\Model\ResourceModel\Helper $resourceHelper * @param \Magento\Framework\Validator\UniversalFactory $universalFactory * @param \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot - * @param ObjectManagerInterface $objectManager + * @param AddressBlock $addressBlock + * @param AllowedCountries $allowedCountryReader * @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection * * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -59,10 +52,12 @@ public function __construct( \Magento\Eav\Model\ResourceModel\Helper $resourceHelper, \Magento\Framework\Validator\UniversalFactory $universalFactory, \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot, - ObjectManagerInterface $objectManager, + AddressBlock $addressBlock, + AllowedCountries $allowedCountryReader, \Magento\Framework\DB\Adapter\AdapterInterface $connection = null ) { - $this->objectManager = $objectManager; + $this->addressBlock = $addressBlock; + $this->allowedCountryReader = $allowedCountryReader; parent::__construct( $entityFactory, @@ -79,19 +74,6 @@ public function __construct( ); } - /** - * Resource initialization - * - * @return void - */ - public function _construct() - { - parent::_construct(); - - $this->addressBlock = $this->objectManager->create(AddressBlock::class); - $this->allowedCountryReader = $this->objectManager->create(AllowedCountries::class); - } - /** * Set allowed country filter for customer's addresses * diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php index 436e7f84de030..58b3f4082585c 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php @@ -32,7 +32,9 @@ public function testSetCustomerFilter() $storeId = $customer->getStoreId(); $allowedCountries = $allowedCountriesObj->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId); $strAllowedCountries = implode("%S, %S", $allowedCountries); - $format = '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)' . + $format = '%AWHERE' . + '%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Scountry_id%S IN(%S' . $strAllowedCountries . '%S))' . + '%SAND%S(%Sparent_id%S = %S-1%S)%SAND%S(%Scountry_id%S IN(%S' . $strAllowedCountries . '%S))' . '%SAND%S(%Sparent_id%S = %S3%S)%SAND%S(%Scountry_id%S IN(%S' . $strAllowedCountries . '%S))%A'; $this->assertStringMatchesFormat($format, (string)$select); } From 0c760fea30c9a83c33f15e014a5cfde7cf42bf07 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Fri, 24 Sep 2021 16:58:56 +0530 Subject: [PATCH 30/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage implemented --- .../Address/StoreAddressCollectionTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php index 58b3f4082585c..f25869262820b 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php @@ -26,16 +26,16 @@ public function testSetCustomerFilter() $collection->setCustomerFilter($customer); $customer->setId(3); $collection->setCustomerFilter($customer); + $this->assertStringMatchesFormat( + '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)%SAND%S(%Sparent_id%S = %S3%S)%A', + (string)$select + ); $allowedCountriesObj = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( \Magento\Directory\Model\AllowedCountries::class ); $storeId = $customer->getStoreId(); $allowedCountries = $allowedCountriesObj->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId); $strAllowedCountries = implode("%S, %S", $allowedCountries); - $format = '%AWHERE' . - '%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Scountry_id%S IN(%S' . $strAllowedCountries . '%S))' . - '%SAND%S(%Sparent_id%S = %S-1%S)%SAND%S(%Scountry_id%S IN(%S' . $strAllowedCountries . '%S))' . - '%SAND%S(%Sparent_id%S = %S3%S)%SAND%S(%Scountry_id%S IN(%S' . $strAllowedCountries . '%S))%A'; - $this->assertStringMatchesFormat($format, (string)$select); + $this->assertStringMatchesFormat('%AWHERE%S(%Scountry_id%S IN(%S' . $strAllowedCountries . '%S))%A', (string)$select); } } From 42eefb5e0720c03cef755339278ca90e4fa1d7af Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Fri, 24 Sep 2021 18:45:01 +0530 Subject: [PATCH 31/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage implemented --- .../ResourceModel/Address/StoreAddressCollectionTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php index f25869262820b..0511ab054e7d8 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php @@ -26,10 +26,6 @@ public function testSetCustomerFilter() $collection->setCustomerFilter($customer); $customer->setId(3); $collection->setCustomerFilter($customer); - $this->assertStringMatchesFormat( - '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)%SAND%S(%Sparent_id%S = %S3%S)%A', - (string)$select - ); $allowedCountriesObj = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( \Magento\Directory\Model\AllowedCountries::class ); From 30b4b4542e168f58bf5c061522e67d4cc16bcc55 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Fri, 24 Sep 2021 20:53:35 +0530 Subject: [PATCH 32/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage implemented --- .../Address/StoreAddressCollectionTest.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php index 0511ab054e7d8..64ae477338d08 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php @@ -29,9 +29,14 @@ public function testSetCustomerFilter() $allowedCountriesObj = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( \Magento\Directory\Model\AllowedCountries::class ); - $storeId = $customer->getStoreId(); - $allowedCountries = $allowedCountriesObj->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId); - $strAllowedCountries = implode("%S, %S", $allowedCountries); - $this->assertStringMatchesFormat('%AWHERE%S(%Scountry_id%S IN(%S' . $strAllowedCountries . '%S))%A', (string)$select); + $format = '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)%SAND%S(%Sparent_id%S = %S3%S)%A'; + $storeId = $customer->getStoreId() ?? null; + if ($storeId) { + $allowedCountries = $allowedCountriesObj->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId); + $strAllowedCountries = implode("%S, %S", $allowedCountries); + $format = '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)' . + '%SAND%S(%Sparent_id%S = %S3%S)%SAND%S(%Scountry_id%S IN(%S' . $strAllowedCountries . '%S))%A'; + } + $this->assertStringMatchesFormat($format, (string)$select); } } From 79c18233a95a1111f1ec1547480b92ed57cec46b Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Mon, 27 Sep 2021 10:02:41 +0530 Subject: [PATCH 33/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage implemented --- .../ResourceModel/Address/StoreAddressCollectionTest.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php index 64ae477338d08..74d4ab0e443e4 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php @@ -26,12 +26,13 @@ public function testSetCustomerFilter() $collection->setCustomerFilter($customer); $customer->setId(3); $collection->setCustomerFilter($customer); - $allowedCountriesObj = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Directory\Model\AllowedCountries::class - ); $format = '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)%SAND%S(%Sparent_id%S = %S3%S)%A'; - $storeId = $customer->getStoreId() ?? null; + + $storeId = $customer->getStoreId() ?? 1; if ($storeId) { + $allowedCountriesObj = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + \Magento\Directory\Model\AllowedCountries::class + ); $allowedCountries = $allowedCountriesObj->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId); $strAllowedCountries = implode("%S, %S", $allowedCountries); $format = '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)' . From 2b4646908760c3a65ff3907bf8ad8a0537cfdd9e Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Mon, 27 Sep 2021 15:40:59 +0530 Subject: [PATCH 34/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage implemented --- .../Model/ResourceModel/Address/StoreAddressCollectionTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php index 74d4ab0e443e4..ee474fd858a46 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php @@ -35,8 +35,7 @@ public function testSetCustomerFilter() ); $allowedCountries = $allowedCountriesObj->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId); $strAllowedCountries = implode("%S, %S", $allowedCountries); - $format = '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)' . - '%SAND%S(%Sparent_id%S = %S3%S)%SAND%S(%Scountry_id%S IN(%S' . $strAllowedCountries . '%S))%A'; + $format = "%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Scountry_id%S IN(%S$strAllowedCountries%S))%A"; } $this->assertStringMatchesFormat($format, (string)$select); } From 0fcac4142d909603612d0601a5a01f6d2fdf24fa Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Tue, 28 Sep 2021 10:07:03 +0530 Subject: [PATCH 35/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings - Integration test coverage implemented --- .../Address/StoreAddressCollectionTest.php | 136 ++++++++++++++---- 1 file changed, 111 insertions(+), 25 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php index ee474fd858a46..3f4570bfa9471 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php @@ -9,34 +9,120 @@ */ namespace Magento\Customer\Model\ResourceModel\Address; -use Magento\Store\Model\ScopeInterface; +use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Framework\App\Config\ConfigResource\ConfigInterface; +use Magento\Framework\App\Config\ReinitableConfigInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Config\Storage\Writer; +use Magento\Framework\App\Config\Storage\WriterInterface; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\ObjectManager; +use PHPUnit\Framework\TestCase; -class StoreAddressCollectionTest extends \PHPUnit\Framework\TestCase +/** + * Assert that only relevant addresses for the allowed countries under a website/store fetch. + * + * @magentoDbIsolation enabled + */ +class StoreAddressCollectionTest extends TestCase { - public function testSetCustomerFilter() + /** + * @var ObjectManager + */ + protected $objectManager; + + /** + * @var CustomerRepositoryInterface + */ + protected $customerRepository; + + /** + * @var StoreAddressCollection + */ + private $storeAddressCollection; + + protected function setUp(): void { - $collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Customer\Model\ResourceModel\Address\StoreAddressCollection::class - ); - $select = $collection->getSelect(); - $this->assertSame($collection, $collection->setCustomerFilter([1, 2])); - $customer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Customer\Model\Customer::class - ); - $collection->setCustomerFilter($customer); - $customer->setId(3); - $collection->setCustomerFilter($customer); - $format = '%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Sparent_id%S = %S-1%S)%SAND%S(%Sparent_id%S = %S3%S)%A'; - - $storeId = $customer->getStoreId() ?? 1; - if ($storeId) { - $allowedCountriesObj = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\Directory\Model\AllowedCountries::class - ); - $allowedCountries = $allowedCountriesObj->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId); - $strAllowedCountries = implode("%S, %S", $allowedCountries); - $format = "%AWHERE%S(%Sparent_id%S IN(%S1%S, %S2%S))%SAND%S(%Scountry_id%S IN(%S$strAllowedCountries%S))%A"; + $this->objectManager = Bootstrap::getObjectManager(); + $this->customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class); + $this->storeAddressCollection = $this->objectManager->create(StoreAddressCollection::class); + } + + /** + * Ensure that config changes are deleted or restored. + */ + protected function tearDown(): void + { + /** @var \Magento\Framework\Registry $registry */ + $registry = $this->objectManager->get(\Magento\Framework\Registry::class); + $registry->unregister('isSecureArea'); + $registry->register('isSecureArea', true); + + /** @var ConfigInterface $config */ + $config = $this->objectManager->get(ConfigInterface::class); + $config->deleteConfig('general/country/allow'); + $this->objectManager->get(ReinitableConfigInterface::class)->reinit(); + + /** @var Writer $configWriter */ + $configWriter = $this->objectManager->get(WriterInterface::class); + + $configWriter->save('customer/account_share/scope', 1); + $scopeConfig = $this->objectManager->get(ScopeConfigInterface::class); + $scopeConfig->clean(); + + $registry->unregister('isSecureArea'); + $registry->register('isSecureArea', false); + parent::tearDown(); + } + + /** + * Assert that only allowed country address fetched. + * + * @magentoDataFixture Magento/Customer/_files/customer.php + * @magentoDataFixture Magento/Customer/_files/customer_address.php + * + * @dataProvider addressesDataProvider + * + * @param $customerId + * @param $allowedCountries + * @return void + * @throws \Magento\Framework\Exception\LocalizedException + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function testSetCustomerFilter($customerId, $allowedCountries) : void + { + /** @var ConfigInterface $config */ + $config = $this->objectManager->get(ConfigInterface::class); + $config->saveConfig('general/country/allow', implode(',', $allowedCountries)); + $this->objectManager->get(ReinitableConfigInterface::class)->reinit(); + + /** @var Writer $configWriter */ + $configWriter = $this->objectManager->get(WriterInterface::class); + $configWriter->save('customer/account_share/scope', 0); + $scopeConfig = $this->objectManager->get(ScopeConfigInterface::class); + $scopeConfig->clean(); + + $customer = $this->customerRepository->getById($customerId); + $addresses = $this->storeAddressCollection->setCustomerFilter($customer); + $this->assertIsArray($addresses->getData()); + + foreach ($addresses->getData() as $address) { + $this->assertContains($address['country_id'], $allowedCountries); } - $this->assertStringMatchesFormat($format, (string)$select); + } + + /** + * Data provider for create allowed or not allowed countries. + * + * @return array + */ + public function addressesDataProvider(): array + { + return [ + 'address_in_single_allowed_country' => [1, ['US']], + 'address_not_in_single_allowed_country' => [1, ['FR']], + 'address_in_multiple_allowed_countries' => [1, ['US', 'IN']], + 'address_not_in_multiple_allowed_countries' => [1, ['FR', 'DE']], + ]; } } From fff50e4f8cdb0740601d48577baa442a3a28aea9 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Thu, 30 Sep 2021 16:34:49 +0530 Subject: [PATCH 36/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings --- .../Attribute/Source/CountryWithWebsites.php | 18 +-- .../Address/AddressAttributeFilter.php | 109 ++++++++++++++++++ .../layout/sales_order_create_index.xml | 6 +- ...rder_create_load_block_billing_address.xml | 3 +- .../sales_order_create_load_block_data.xml | 6 +- ...der_create_load_block_shipping_address.xml | 3 +- .../templates/order/create/form/address.phtml | 6 +- 7 files changed, 134 insertions(+), 17 deletions(-) create mode 100644 app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php b/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php index 0522c042cbd77..b9765d7a394f0 100644 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php +++ b/app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php @@ -22,6 +22,8 @@ use Magento\Framework\App\ObjectManager; use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; +use Magento\Framework\App\Request\Http; +use Magento\Customer\Api\CustomerRepositoryInterface; /** * Return allowed countries for specified website @@ -54,12 +56,12 @@ class CountryWithWebsites extends Table private $shareConfig; /** - * @var \Magento\Framework\App\Request\Http + * @var Http */ private $request; /** - * @var \Magento\Customer\Api\CustomerRepositoryInterface + * @var CustomerRepositoryInterface */ private $customerRepository; @@ -70,8 +72,8 @@ class CountryWithWebsites extends Table * @param AllowedCountries $allowedCountriesReader * @param StoreManagerInterface $storeManager * @param Share $shareConfig - * @param \Magento\Framework\App\Request\Http|null $request - * @param \Magento\Customer\Api\CustomerRepositoryInterface|null $customerRepository + * @param Http|null $request + * @param CustomerRepositoryInterface|null $customerRepository */ public function __construct( OptionCollectionFactory $attrOptionCollectionFactory, @@ -80,17 +82,17 @@ public function __construct( AllowedCountries $allowedCountriesReader, StoreManagerInterface $storeManager, CustomerShareConfig $shareConfig, - ?\Magento\Framework\App\Request\Http $request = null, - ?\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository = null + ?Http $request = null, + ?CustomerRepositoryInterface $customerRepository = null ) { $this->countriesFactory = $countriesFactory; $this->allowedCountriesReader = $allowedCountriesReader; $this->storeManager = $storeManager; $this->shareConfig = $shareConfig; $this->request = $request - ?? ObjectManager::getInstance()->get(\Magento\Framework\App\Request\Http::class); + ?? ObjectManager::getInstance()->get(Http::class); $this->customerRepository = $customerRepository - ?? ObjectManager::getInstance()->get(\Magento\Customer\Api\CustomerRepositoryInterface::class); + ?? ObjectManager::getInstance()->get(CustomerRepositoryInterface::class); parent::__construct($attrOptionCollectionFactory, $attrOptionFactory); } diff --git a/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php b/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php new file mode 100644 index 0000000000000..8b90d2c259e1e --- /dev/null +++ b/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php @@ -0,0 +1,109 @@ +allowedCountryReader = $allowedCountryReader; + $this->collection = $collection; + + parent::__construct( + $entityFactory, + $logger, + $fetchStrategy, + $eventManager, + $eavConfig, + $resource, + $eavEntityFactory, + $resourceHelper, + $universalFactory, + $entitySnapshot, + $connection + ); + } + + /** + * Resource initialization + * + * @return void + */ + protected function _construct() + { + $this->_init(\Magento\Customer\Model\Address::class, \Magento\Customer\Model\ResourceModel\Address::class); + } + + /** + * Set allowed country filter for customer's addresses + * + * @return $this|Object + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function setScopeFilter($storeId) + { + if ($storeId) { + $allowedCountries = $this->allowedCountryReader->getAllowedCountries( + ScopeInterface::SCOPE_STORE, + $storeId + ); + $this->collection->addAttributeToFilter('country_id', ['in' => $allowedCountries]); + } + + return $this->collection; + } +} diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml index c8f88ea1e4a81..a5d28437a45b4 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml @@ -48,13 +48,15 @@ Magento\Sales\ViewModel\Customer\AddressFormatter - Magento\Customer\Model\ResourceModel\Address\StoreAddressCollection + Magento\Customer\Model\ResourceModel\Address\Collection + Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter Magento\Sales\ViewModel\Customer\AddressFormatter - Magento\Customer\Model\ResourceModel\Address\StoreAddressCollection + Magento\Customer\Model\ResourceModel\Address\Collection + Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_billing_address.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_billing_address.xml index cc417882cee24..229cad2d122d0 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_billing_address.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_billing_address.xml @@ -11,8 +11,9 @@ Magento\Sales\ViewModel\Customer\AddressFormatter - Magento\Customer\Model\ResourceModel\Address\StoreAddressCollection + Magento\Customer\Model\ResourceModel\Address\Collection Magento\Sales\ViewModel\Customer\Address\Billing\AddressDataProvider + Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_data.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_data.xml index fe5add54f9474..6b0f09f4bfb74 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_data.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_data.xml @@ -23,13 +23,15 @@ Magento\Sales\ViewModel\Customer\AddressFormatter - Magento\Customer\Model\ResourceModel\Address\StoreAddressCollection + Magento\Customer\Model\ResourceModel\Address\Collection + Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter Magento\Sales\ViewModel\Customer\AddressFormatter - Magento\Customer\Model\ResourceModel\Address\StoreAddressCollection + Magento\Customer\Model\ResourceModel\Address\Collection + Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_shipping_address.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_shipping_address.xml index 766bea6f4278a..bcc51db8124a0 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_shipping_address.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_shipping_address.xml @@ -11,7 +11,8 @@ Magento\Sales\ViewModel\Customer\AddressFormatter - Magento\Customer\Model\ResourceModel\Address\StoreAddressCollection + Magento\Customer\Model\ResourceModel\Address\Collection + Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter diff --git a/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml b/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml index 79bc1e3a8df36..37ef8b1ef1a39 100644 --- a/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml +++ b/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml @@ -10,13 +10,13 @@ */ /** - * @var \Magento\Customer\Model\ResourceModel\Address\Collection $addressCollection + * @var $viewModel \Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter */ -$addressCollection = $block->getData('customerAddressCollection'); +$viewModel = $block->getViewModel(); $addressArray = []; if ($block->getCustomerId()): - $addressArray = $addressCollection->setCustomerFilter([$block->getCustomerId()])->toArray(); + $addressArray = $viewModel->setScopeFilter($block->getStoreId())->setCustomerFilter([$block->getCustomerId()])->toArray(); endif; /** From bf1eb886fb4ff4dbdfba32a972eeb71242be90fc Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Thu, 30 Sep 2021 18:45:37 +0530 Subject: [PATCH 37/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings --- .../Address/AddressAttributeFilter.php | 72 +++---------------- .../templates/order/create/form/address.phtml | 6 +- 2 files changed, 15 insertions(+), 63 deletions(-) diff --git a/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php b/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php index 8b90d2c259e1e..33a68e7b7b901 100644 --- a/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php +++ b/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php @@ -10,13 +10,14 @@ use Magento\Customer\Model\ResourceModel\Address\Collection; use Magento\Directory\Model\AllowedCountries; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\View\Element\Block\ArgumentInterface; use Magento\Store\Model\ScopeInterface; /** * Customer's addresses filter as per allowed country filter for corresponding store */ -class AddressAttributeFilter extends \Magento\Eav\Model\Entity\Collection\VersionControl\AbstractCollection implements ArgumentInterface +class AddressAttributeFilter implements ArgumentInterface { /** * @var AllowedCountries @@ -24,86 +25,33 @@ class AddressAttributeFilter extends \Magento\Eav\Model\Entity\Collection\Versio private $allowedCountryReader; /** - * @var Collection - */ - private $collection; - - /** - * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory - * @param \Psr\Log\LoggerInterface $logger - * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy - * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Eav\Model\Config $eavConfig - * @param \Magento\Framework\App\ResourceConnection $resource - * @param \Magento\Eav\Model\EntityFactory $eavEntityFactory - * @param \Magento\Eav\Model\ResourceModel\Helper $resourceHelper - * @param \Magento\Framework\Validator\UniversalFactory $universalFactory - * @param \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot * @param AllowedCountries $allowedCountryReader - * @param Collection $collection - * @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection - * - * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( - \Magento\Framework\Data\Collection\EntityFactory $entityFactory, - \Psr\Log\LoggerInterface $logger, - \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, - \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Eav\Model\Config $eavConfig, - \Magento\Framework\App\ResourceConnection $resource, - \Magento\Eav\Model\EntityFactory $eavEntityFactory, - \Magento\Eav\Model\ResourceModel\Helper $resourceHelper, - \Magento\Framework\Validator\UniversalFactory $universalFactory, - \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot, - AllowedCountries $allowedCountryReader, - Collection $collection, - \Magento\Framework\DB\Adapter\AdapterInterface $connection = null + AllowedCountries $allowedCountryReader ) { $this->allowedCountryReader = $allowedCountryReader; - $this->collection = $collection; - - parent::__construct( - $entityFactory, - $logger, - $fetchStrategy, - $eventManager, - $eavConfig, - $resource, - $eavEntityFactory, - $resourceHelper, - $universalFactory, - $entitySnapshot, - $connection - ); } - /** - * Resource initialization - * - * @return void - */ - protected function _construct() - { - $this->_init(\Magento\Customer\Model\Address::class, \Magento\Customer\Model\ResourceModel\Address::class); - } /** * Set allowed country filter for customer's addresses * - * @return $this|Object - * @throws \Magento\Framework\Exception\LocalizedException + * @param Collection $collection + * @param $storeId + * @return Object + * @throws LocalizedException */ - public function setScopeFilter($storeId) + public function setScopeFilter(Collection $collection, $storeId) { if ($storeId) { $allowedCountries = $this->allowedCountryReader->getAllowedCountries( ScopeInterface::SCOPE_STORE, $storeId ); - $this->collection->addAttributeToFilter('country_id', ['in' => $allowedCountries]); + $collection->addAttributeToFilter('country_id', ['in' => $allowedCountries]); } - return $this->collection; + return $collection; } } diff --git a/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml b/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml index 37ef8b1ef1a39..28d8e2844630b 100644 --- a/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml +++ b/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml @@ -10,13 +10,17 @@ */ /** + * @var \Magento\Customer\Model\ResourceModel\Address\Collection $addressCollection * @var $viewModel \Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter */ + +$addressCollection = $block->getData('customerAddressCollection'); $viewModel = $block->getViewModel(); $addressArray = []; if ($block->getCustomerId()): - $addressArray = $viewModel->setScopeFilter($block->getStoreId())->setCustomerFilter([$block->getCustomerId()])->toArray(); + $addressArray = $viewModel->setScopeFilter($addressCollection, $block->getStoreId()) + ->setCustomerFilter([$block->getCustomerId()])->toArray(); endif; /** From fd54337f7b8ff27e6a50450d3bff39450925a27e Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Thu, 30 Sep 2021 19:52:48 +0530 Subject: [PATCH 38/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings --- .../ViewModel/Customer/Address/AddressAttributeFilter.php | 1 - .../view/adminhtml/templates/order/create/form/address.phtml | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php b/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php index 33a68e7b7b901..9428706fa02b2 100644 --- a/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php +++ b/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php @@ -33,7 +33,6 @@ public function __construct( $this->allowedCountryReader = $allowedCountryReader; } - /** * Set allowed country filter for customer's addresses * diff --git a/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml b/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml index 28d8e2844630b..fd96b1948beea 100644 --- a/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml +++ b/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml @@ -10,8 +10,8 @@ */ /** - * @var \Magento\Customer\Model\ResourceModel\Address\Collection $addressCollection - * @var $viewModel \Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter + * @var \Magento\Customer\Model\ResourceModel\Address\Collection $addressCollection + * @var \Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter $viewModel */ $addressCollection = $block->getData('customerAddressCollection'); From f6da342af12af9bbf1273c4a4ac42bc399709462 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Fri, 1 Oct 2021 12:29:02 +0530 Subject: [PATCH 39/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings --- .../Address/StoreAddressCollection.php | 98 ------------------- .../Address/AddressAttributeFilter.php | 2 +- .../Address/AddressAttributeFilterTest.php} | 40 +++++--- 3 files changed, 26 insertions(+), 114 deletions(-) delete mode 100644 app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php rename dev/tests/integration/testsuite/Magento/{Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php => Sales/ViewModel/Customer/Address/AddressAttributeFilterTest.php} (75%) diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php b/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php deleted file mode 100644 index bfde6c5a89c3a..0000000000000 --- a/app/code/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollection.php +++ /dev/null @@ -1,98 +0,0 @@ -addressBlock = $addressBlock; - $this->allowedCountryReader = $allowedCountryReader; - - parent::__construct( - $entityFactory, - $logger, - $fetchStrategy, - $eventManager, - $eavConfig, - $resource, - $eavEntityFactory, - $resourceHelper, - $universalFactory, - $entitySnapshot, - $connection - ); - } - - /** - * Set allowed country filter for customer's addresses - * - * @param \Magento\Customer\Model\Customer|array $customer - * @return $this|Object - * @throws \Magento\Framework\Exception\LocalizedException - */ - public function setCustomerFilter($customer) - { - parent::setCustomerFilter($customer); - - $storeId = $this->addressBlock->getStoreId() ?? null; - if ($storeId) { - $allowedCountries = $this->allowedCountryReader->getAllowedCountries( - ScopeInterface::SCOPE_STORE, - $storeId - ); - $this->addAttributeToFilter('country_id', ['in' => $allowedCountries]); - } - return $this; - } -} diff --git a/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php b/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php index 9428706fa02b2..b1a77e53b45b0 100644 --- a/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php +++ b/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php @@ -37,7 +37,7 @@ public function __construct( * Set allowed country filter for customer's addresses * * @param Collection $collection - * @param $storeId + * @param string|integer $storeId * @return Object * @throws LocalizedException */ diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php b/dev/tests/integration/testsuite/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilterTest.php similarity index 75% rename from dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php rename to dev/tests/integration/testsuite/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilterTest.php index 3f4570bfa9471..c796a572a31e4 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/Address/StoreAddressCollectionTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilterTest.php @@ -7,14 +7,18 @@ /** * Tests for customer addresses collection */ -namespace Magento\Customer\Model\ResourceModel\Address; +namespace Magento\Sales\ViewModel\Customer\Address; +use Magento\Customer\Model\ResourceModel\Address\Collection; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Framework\App\Config\ConfigResource\ConfigInterface; use Magento\Framework\App\Config\ReinitableConfigInterface; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Config\Storage\Writer; use Magento\Framework\App\Config\Storage\WriterInterface; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Registry; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\ObjectManager; use PHPUnit\Framework\TestCase; @@ -23,8 +27,9 @@ * Assert that only relevant addresses for the allowed countries under a website/store fetch. * * @magentoDbIsolation enabled + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class StoreAddressCollectionTest extends TestCase +class AddressAttributeFilterTest extends TestCase { /** * @var ObjectManager @@ -37,15 +42,21 @@ class StoreAddressCollectionTest extends TestCase protected $customerRepository; /** - * @var StoreAddressCollection + * @var AddressAttributeFilter */ - private $storeAddressCollection; + private $scopeFilter; + + /** + * @var Collection + */ + private $collection; protected function setUp(): void { $this->objectManager = Bootstrap::getObjectManager(); $this->customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class); - $this->storeAddressCollection = $this->objectManager->create(StoreAddressCollection::class); + $this->collection = $this->objectManager->get(Collection::class); + $this->scopeFilter = $this->objectManager->create(AddressAttributeFilter::class); } /** @@ -53,8 +64,8 @@ protected function setUp(): void */ protected function tearDown(): void { - /** @var \Magento\Framework\Registry $registry */ - $registry = $this->objectManager->get(\Magento\Framework\Registry::class); + /** @var Registry $registry */ + $registry = $this->objectManager->get(Registry::class); $registry->unregister('isSecureArea'); $registry->register('isSecureArea', true); @@ -83,13 +94,14 @@ protected function tearDown(): void * * @dataProvider addressesDataProvider * + * @param Collection $collection * @param $customerId * @param $allowedCountries * @return void - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Magento\Framework\Exception\NoSuchEntityException + * @throws LocalizedException + * @throws NoSuchEntityException */ - public function testSetCustomerFilter($customerId, $allowedCountries) : void + public function testSetScopeFilter($storeId, $allowedCountries) : void { /** @var ConfigInterface $config */ $config = $this->objectManager->get(ConfigInterface::class); @@ -102,8 +114,7 @@ public function testSetCustomerFilter($customerId, $allowedCountries) : void $scopeConfig = $this->objectManager->get(ScopeConfigInterface::class); $scopeConfig->clean(); - $customer = $this->customerRepository->getById($customerId); - $addresses = $this->storeAddressCollection->setCustomerFilter($customer); + $addresses = $this->scopeFilter->setScopeFilter($this->collection, $storeId); $this->assertIsArray($addresses->getData()); foreach ($addresses->getData() as $address) { @@ -112,17 +123,16 @@ public function testSetCustomerFilter($customerId, $allowedCountries) : void } /** - * Data provider for create allowed or not allowed countries. + * Data provider for create allowed countries for a particular store. * + * @param Collection $collection * @return array */ public function addressesDataProvider(): array { return [ 'address_in_single_allowed_country' => [1, ['US']], - 'address_not_in_single_allowed_country' => [1, ['FR']], 'address_in_multiple_allowed_countries' => [1, ['US', 'IN']], - 'address_not_in_multiple_allowed_countries' => [1, ['FR', 'DE']], ]; } } From e438e743c9a709d3002c24af7922f7ab8d589aa9 Mon Sep 17 00:00:00 2001 From: "pradeep.rauthan" Date: Sat, 2 Oct 2021 09:11:44 +0530 Subject: [PATCH 40/40] MC-42623:Countries list is incorrect when using different countries per website and Global Customer Account settings --- .../Customer/Address/AddressAttributeFilter.php | 4 ++-- .../adminhtml/layout/sales_order_create_index.xml | 4 ++-- ...es_order_create_load_block_billing_address.xml | 2 +- .../layout/sales_order_create_load_block_data.xml | 4 ++-- ...s_order_create_load_block_shipping_address.xml | 2 +- .../templates/order/create/form/address.phtml | 4 ++-- .../Address/CustomerAddressDataProviderTest.php | 15 ++++++++------- .../Address/AddressAttributeFilterTest.php | 5 +---- 8 files changed, 19 insertions(+), 21 deletions(-) diff --git a/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php b/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php index b1a77e53b45b0..028248ff347a5 100644 --- a/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php +++ b/app/code/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilter.php @@ -38,10 +38,10 @@ public function __construct( * * @param Collection $collection * @param string|integer $storeId - * @return Object + * @return Collection * @throws LocalizedException */ - public function setScopeFilter(Collection $collection, $storeId) + public function setScopeFilter(Collection $collection, $storeId) : Collection { if ($storeId) { $allowedCountries = $this->allowedCountryReader->getAllowedCountries( diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml index a5d28437a45b4..7a593a12be575 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml @@ -49,14 +49,14 @@ Magento\Sales\ViewModel\Customer\AddressFormatter Magento\Customer\Model\ResourceModel\Address\Collection - Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter + Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter Magento\Sales\ViewModel\Customer\AddressFormatter Magento\Customer\Model\ResourceModel\Address\Collection - Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter + Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_billing_address.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_billing_address.xml index 229cad2d122d0..64dc60fa952bb 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_billing_address.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_billing_address.xml @@ -13,7 +13,7 @@ Magento\Sales\ViewModel\Customer\AddressFormatter Magento\Customer\Model\ResourceModel\Address\Collection Magento\Sales\ViewModel\Customer\Address\Billing\AddressDataProvider - Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter + Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_data.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_data.xml index 6b0f09f4bfb74..a75b58bceb2ba 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_data.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_data.xml @@ -24,14 +24,14 @@ Magento\Sales\ViewModel\Customer\AddressFormatter Magento\Customer\Model\ResourceModel\Address\Collection - Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter + Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter Magento\Sales\ViewModel\Customer\AddressFormatter Magento\Customer\Model\ResourceModel\Address\Collection - Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter + Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_shipping_address.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_shipping_address.xml index bcc51db8124a0..49de5cfb79776 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_shipping_address.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_shipping_address.xml @@ -12,7 +12,7 @@ Magento\Sales\ViewModel\Customer\AddressFormatter Magento\Customer\Model\ResourceModel\Address\Collection - Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter + Magento\Sales\ViewModel\Customer\Address\AddressAttributeFilter diff --git a/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml b/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml index fd96b1948beea..5950d7a08bba6 100644 --- a/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml +++ b/app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml @@ -15,11 +15,11 @@ */ $addressCollection = $block->getData('customerAddressCollection'); -$viewModel = $block->getViewModel(); +$AddressCollectionAttributeFilter = $block->getData('customerAddressCollectionAttributeFilter'); $addressArray = []; if ($block->getCustomerId()): - $addressArray = $viewModel->setScopeFilter($addressCollection, $block->getStoreId()) + $addressArray = $AddressCollectionAttributeFilter->setScopeFilter($addressCollection, $block->getStoreId()) ->setCustomerFilter([$block->getCustomerId()])->toArray(); endif; diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php index 12fa4ed809bf3..146a65c2970e8 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/Address/CustomerAddressDataProviderTest.php @@ -7,20 +7,21 @@ namespace Magento\Customer\Model\Address; -use Magento\TestFramework\Helper\Bootstrap; -use Magento\TestFramework\ObjectManager; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Framework\App\Config\ConfigResource\ConfigInterface; use Magento\Framework\App\Config\ReinitableConfigInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Config\Storage\Writer; use Magento\Framework\App\Config\Storage\WriterInterface; -use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Registry; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\ObjectManager; use PHPUnit\Framework\TestCase; /** - * Assert that only relavant addresses for the allowed countries under a website/store fetch. + * Assert that only relevant addresses for the allowed countries under a website/store fetch. * - * @magentoDbIsolation enabled + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class CustomerAddressDataProviderTest extends TestCase { @@ -51,8 +52,8 @@ protected function setUp(): void */ protected function tearDown(): void { - /** @var \Magento\Framework\Registry $registry */ - $registry = $this->objectManager->get(\Magento\Framework\Registry::class); + /** @var Registry $registry */ + $registry = $this->objectManager->get(Registry::class); $registry->unregister('isSecureArea'); $registry->register('isSecureArea', true); diff --git a/dev/tests/integration/testsuite/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilterTest.php b/dev/tests/integration/testsuite/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilterTest.php index c796a572a31e4..44c4d21b58163 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilterTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/ViewModel/Customer/Address/AddressAttributeFilterTest.php @@ -26,7 +26,6 @@ /** * Assert that only relevant addresses for the allowed countries under a website/store fetch. * - * @magentoDbIsolation enabled * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class AddressAttributeFilterTest extends TestCase @@ -94,8 +93,7 @@ protected function tearDown(): void * * @dataProvider addressesDataProvider * - * @param Collection $collection - * @param $customerId + * @param $storeId * @param $allowedCountries * @return void * @throws LocalizedException @@ -125,7 +123,6 @@ public function testSetScopeFilter($storeId, $allowedCountries) : void /** * Data provider for create allowed countries for a particular store. * - * @param Collection $collection * @return array */ public function addressesDataProvider(): array