Skip to content

Commit 7024054

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

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
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, (int)$customer->getStoreId())) {
908+
if (!$this->isAddressAllowedForWebsite($address, (string)$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 int $storeId
1622+
* @param string $storeId
16231623
* @return bool
16241624
*/
1625-
private function isAddressAllowedForWebsite(AddressInterface $address, int $storeId): bool
1625+
private function isAddressAllowedForWebsite(AddressInterface $address, string $storeId): bool
16261626
{
16271627
$allowedCountries = $this->allowedCountriesReader->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId);
16281628

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ class Quote extends AbstractExtensibleModel implements \Magento\Quote\Api\Data\C
410410
* @param \Magento\Sales\Model\OrderIncrementIdChecker|null $orderIncrementIdChecker
411411
* @param AllowedCountries|null $allowedCountriesReader
412412
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
413-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
414413
*/
415414
public function __construct(
416415
\Magento\Framework\Model\Context $context,
@@ -931,7 +930,6 @@ public function assignCustomer(\Magento\Customer\Api\Data\CustomerInterface $cus
931930
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
932931
* @param Address $billingAddress Quote billing address
933932
* @param Address $shippingAddress Quote shipping address
934-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
935933
* @return $this
936934
*/
937935
public function assignCustomerWithAddressChange(
@@ -954,10 +952,7 @@ public function assignCustomerWithAddressChange(
954952
/** @var \Magento\Quote\Model\Quote\Address $billingAddress */
955953
$billingAddress = $this->_quoteAddressFactory->create();
956954
$billingAddress->importCustomerAddressData($defaultBillingAddress);
957-
958-
if ($this->isAddressAllowedForWebsite($billingAddress, (int)$this->getStoreId())) {
959-
$this->setBillingAddress($billingAddress);
960-
}
955+
$this->assignAddress($billingAddress);
961956
}
962957
}
963958

@@ -975,9 +970,8 @@ public function assignCustomerWithAddressChange(
975970
$shippingAddress = $this->_quoteAddressFactory->create();
976971
}
977972
}
978-
if ($this->isAddressAllowedForWebsite($shippingAddress, (int)$this->getStoreId())) {
979-
$this->setShippingAddress($shippingAddress);
980-
}
973+
974+
$this->assignAddress($shippingAddress, false);
981975
}
982976

983977
return $this;
@@ -2619,13 +2613,29 @@ public function setExtensionAttributes(\Magento\Quote\Api\Data\CartExtensionInte
26192613
* Check is address allowed for store
26202614
*
26212615
* @param Address $address
2622-
* @param int $storeId
2616+
* @param string $storeId
26232617
* @return bool
26242618
*/
2625-
private function isAddressAllowedForWebsite(Address $address, int $storeId): bool
2619+
private function isAddressAllowedForWebsite(Address $address, string $storeId): bool
26262620
{
26272621
$allowedCountries = $this->allowedCountriesReader->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId);
26282622

26292623
return in_array($address->getCountryId(), $allowedCountries);
26302624
}
2625+
2626+
/**
2627+
* Assign address to quote
2628+
*
2629+
* @param Address $address
2630+
* @param bool $billingAddress
2631+
* @return void
2632+
*/
2633+
private function assignAddress(Address $address, bool $billingAddress = true): void
2634+
{
2635+
if ($this->isAddressAllowedForWebsite($address, (string) $this->getStoreId())) {
2636+
$billingAddress
2637+
? $this->setBillingAddress($address)
2638+
: $this->setShippingAddress($address);
2639+
}
2640+
}
26312641
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -862,18 +862,11 @@ public function testCreateNewCustomerWithPasswordHash()
862862
*/
863863
public function testCreateNewCustomerWithPasswordHashWithNotAllowedCountry()
864864
{
865-
/** Preconditions:
866-
* Customer with two addresses created
867-
* Two websites with different allowed country configured
868-
*/
869-
$customerRepository = $this->objectManager->create(
870-
CustomerRepositoryInterface::class
871-
);
872865
$fixtureCustomerId = 1;
873866
$allowedCountryIdForSecondWebsite = 'UA';
874867
/** @var \Magento\Customer\Model\Customer $customer */
875-
$store =$this->storeManager->getStore('fixture_second_store');
876-
$customerData = $customerRepository->getById($fixtureCustomerId);
868+
$store = $this->storeManager->getStore('fixture_second_store');
869+
$customerData = $this->customerRepository->getById($fixtureCustomerId);
877870
$customerData->getAddresses()[1]->setRegion(null)->setCountryId($allowedCountryIdForSecondWebsite)
878871
->setRegionId(null);
879872
$customerData->setStoreId($store->getId())->setWebsiteId($store->getWebsiteId())->setId(null);

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,16 +353,11 @@ public function testAssignCustomerWithAddressChange(): void
353353
*/
354354
public function testAssignCustomerWithAddressChangeWithNotAllowedCountry()
355355
{
356-
/** Preconditions:
357-
* Customer with address is created
358-
*/
359356
$this->config->saveConfig(
360357
$this->allowedCountriesConfigPath,
361358
'FR'
362359
);
363360
Bootstrap::getObjectManager()->get(ReinitableConfigInterface::class)->reinit();
364-
Bootstrap::getObjectManager()->create(StoreManagerInterface::class)->reinitStores();
365-
366361
/** @var Quote $quote */
367362
$quote = $this->objectManager->create(Quote::class);
368363
$customerData = $this->_prepareQuoteForTestAssignCustomerWithAddressChange($quote);

0 commit comments

Comments
 (0)