Skip to content

Commit df5d914

Browse files
committed
MAGETWO-98832: Multistore Allowed Countries List Problem
1 parent 7024054 commit df5d914

File tree

6 files changed

+44
-21
lines changed

6 files changed

+44
-21
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
905905
}
906906
try {
907907
foreach ($customerAddresses as $address) {
908-
if (!$this->isAddressAllowedForWebsite($address, (string)$customer->getStoreId())) {
908+
if (!$this->isAddressAllowedForWebsite($address, $customer->getStoreId())) {
909909
continue;
910910
}
911911
if ($address->getId()) {
@@ -1619,10 +1619,10 @@ private function setIgnoreValidationFlag($customer)
16191619
* Check is address allowed for store
16201620
*
16211621
* @param AddressInterface $address
1622-
* @param string $storeId
1622+
* @param int|null $storeId
16231623
* @return bool
16241624
*/
1625-
private function isAddressAllowedForWebsite(AddressInterface $address, string $storeId): bool
1625+
private function isAddressAllowedForWebsite(AddressInterface $address, $storeId): bool
16261626
{
16271627
$allowedCountries = $this->allowedCountriesReader->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId);
16281628

app/code/Magento/Quote/Model/Quote.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,10 +2613,10 @@ public function setExtensionAttributes(\Magento\Quote\Api\Data\CartExtensionInte
26132613
* Check is address allowed for store
26142614
*
26152615
* @param Address $address
2616-
* @param string $storeId
2616+
* @param int|null $storeId
26172617
* @return bool
26182618
*/
2619-
private function isAddressAllowedForWebsite(Address $address, string $storeId): bool
2619+
private function isAddressAllowedForWebsite(Address $address, $storeId): bool
26202620
{
26212621
$allowedCountries = $this->allowedCountriesReader->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId);
26222622

@@ -2627,13 +2627,13 @@ private function isAddressAllowedForWebsite(Address $address, string $storeId):
26272627
* Assign address to quote
26282628
*
26292629
* @param Address $address
2630-
* @param bool $billingAddress
2630+
* @param bool $isBillingAddress
26312631
* @return void
26322632
*/
2633-
private function assignAddress(Address $address, bool $billingAddress = true): void
2633+
private function assignAddress(Address $address, bool $isBillingAddress = true): void
26342634
{
2635-
if ($this->isAddressAllowedForWebsite($address, (string) $this->getStoreId())) {
2636-
$billingAddress
2635+
if ($this->isAddressAllowedForWebsite($address, $this->getStoreId())) {
2636+
$isBillingAddress
26372637
? $this->setBillingAddress($address)
26382638
: $this->setShippingAddress($address);
26392639
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types = 1);
7+
8+
use Magento\Framework\App\Config\ConfigResource\ConfigInterface;
9+
use Magento\Framework\App\Config\ReinitableConfigInterface;
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
12+
$objectManager = Bootstrap::getObjectManager();
13+
/** @var ConfigInterface $config */
14+
$config = $objectManager->get(ConfigInterface::class);
15+
$config->saveConfig('general/country/allow', 'FR');
16+
$objectManager->get(ReinitableConfigInterface::class)->reinit();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types = 1);
7+
8+
use Magento\Framework\App\Config\ConfigResource\ConfigInterface;
9+
use Magento\Framework\App\Config\ReinitableConfigInterface;
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
12+
$objectManager = Bootstrap::getObjectManager();
13+
/** @var ConfigInterface $config */
14+
$config = $objectManager->get(ConfigInterface::class);
15+
$config->deleteConfig('general/country/allow');
16+
$objectManager->get(ReinitableConfigInterface::class)->reinit();

dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagementTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,11 +862,10 @@ public function testCreateNewCustomerWithPasswordHash()
862862
*/
863863
public function testCreateNewCustomerWithPasswordHashWithNotAllowedCountry()
864864
{
865-
$fixtureCustomerId = 1;
865+
$customerId = 1;
866866
$allowedCountryIdForSecondWebsite = 'UA';
867-
/** @var \Magento\Customer\Model\Customer $customer */
868867
$store = $this->storeManager->getStore('fixture_second_store');
869-
$customerData = $this->customerRepository->getById($fixtureCustomerId);
868+
$customerData = $this->customerRepository->getById($customerId);
870869
$customerData->getAddresses()[1]->setRegion(null)->setCountryId($allowedCountryIdForSecondWebsite)
871870
->setRegionId(null);
872871
$customerData->setStoreId($store->getId())->setWebsiteId($store->getWebsiteId())->setId(null);

dev/tests/integration/testsuite/Magento/Quote/Model/QuoteTest.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,27 +349,19 @@ public function testAssignCustomerWithAddressChange(): void
349349
*
350350
* @magentoDataFixture Magento/Customer/_files/customer.php
351351
* @magentoDataFixture Magento/Customer/_files/customer_address.php
352+
* @magentoDataFixture Magento/Backend/_files/allowed_countries_fr.php
352353
* @return void
353354
*/
354355
public function testAssignCustomerWithAddressChangeWithNotAllowedCountry()
355356
{
356-
$this->config->saveConfig(
357-
$this->allowedCountriesConfigPath,
358-
'FR'
359-
);
360-
Bootstrap::getObjectManager()->get(ReinitableConfigInterface::class)->reinit();
361357
/** @var Quote $quote */
362358
$quote = $this->objectManager->create(Quote::class);
363359
$customerData = $this->_prepareQuoteForTestAssignCustomerWithAddressChange($quote);
364-
365-
/** Execute SUT */
366360
$quote->assignCustomerWithAddressChange($customerData);
367361

368362
/** Check that addresses are empty */
369363
$this->assertNull($quote->getBillingAddress()->getCountryId());
370364
$this->assertNull($quote->getShippingAddress()->getCountryId());
371-
372-
$this->config->deleteConfig($this->allowedCountriesConfigPath);
373365
}
374366

375367
/**

0 commit comments

Comments
 (0)