Skip to content

Commit e22304a

Browse files
committed
MAGETWO-91626: Countries from default website set when edit order address
- Set store id to address
1 parent 043462f commit e22304a

File tree

6 files changed

+25
-11
lines changed

6 files changed

+25
-11
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Directory\Model\AllowedCountries;
1111
use Magento\Framework\Validation\ValidationResultFactory;
1212
use Magento\Quote\Model\Quote;
13+
use Magento\Store\Model\ScopeInterface;
1314

1415
/**
1516
* @inheritdoc
@@ -54,10 +55,15 @@ public function validate(Quote $quote): array
5455
$validationErrors = [];
5556

5657
if (!$quote->isVirtual()) {
58+
$shippingAddress = $quote->getShippingAddress();
59+
$shippingAddress->setStoreId($quote->getStoreId());
5760
$validationResult =
5861
in_array(
59-
$quote->getShippingAddress()->getCountryId(),
60-
$this->allowedCountryReader->getAllowedCountries()
62+
$shippingAddress->getCountryId(),
63+
$this->allowedCountryReader->getAllowedCountries(
64+
ScopeInterface::SCOPE_STORE,
65+
$quote->getStoreId()
66+
)
6167
);
6268
if (!$validationResult) {
6369
$validationErrors = [__($this->generalMessage)];

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public function __construct(
4343
public function validate(Quote $quote): array
4444
{
4545
$validationErrors = [];
46-
$validationResult = $quote->getBillingAddress()->validate();
46+
$billingAddress = $quote->getBillingAddress();
47+
$billingAddress->setStoreId($quote->getStoreId());
48+
$validationResult = $billingAddress->validate();
4749
if ($validationResult !== true) {
4850
$validationErrors = [__($this->generalMessage)];
4951
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public function validate(Quote $quote): array
4545
$validationErrors = [];
4646

4747
if (!$quote->isVirtual()) {
48-
$validationResult = $quote->getShippingAddress()->validate();
48+
$shippingAddress = $quote->getShippingAddress();
49+
$shippingAddress->setStoreId($quote->getStoreId());
50+
$validationResult = $shippingAddress->validate();
4951
if ($validationResult !== true) {
5052
$validationErrors = [__($this->generalMessage)];
5153
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ public function validate(Quote $quote): array
4545
$validationErrors = [];
4646

4747
if (!$quote->isVirtual()) {
48-
$shippingMethod = $quote->getShippingAddress()->getShippingMethod();
49-
$shippingRate = $quote->getShippingAddress()->getShippingRateByCode($shippingMethod);
48+
$shippingAddress = $quote->getShippingAddress();
49+
$shippingAddress->setStoreId($quote->getStoreId());
50+
$shippingMethod = $shippingAddress->getShippingMethod();
51+
$shippingRate = $shippingAddress->getShippingRateByCode($shippingMethod);
5052
$validationResult = $shippingMethod && $shippingRate;
5153
if (!$validationResult) {
5254
$validationErrors = [__($this->generalMessage)];

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testValidateBeforeSubmitCountryIsNotAllowed()
5757
)->setValue(
5858
'general/country/allow',
5959
'US',
60-
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES
60+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
6161
);
6262
$quote = $this->getQuote();
6363
$quote->getShippingAddress()->setCountryId('AF');
@@ -139,6 +139,7 @@ public function testValidateBeforeSubmitWithMinimumOrderAmount()
139139
* for the another website with different country restrictions.
140140
*
141141
* @magentoDataFixture Magento/Quote/Fixtures/quote_sec_website.php
142+
* @magentoDbIsolation disabled
142143
*/
143144
public function testValidateBeforeSubmit()
144145
{

dev/tests/integration/testsuite/Magento/Store/_files/websites_different_countries_rollback.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@
1313
use Magento\Framework\App\Config\ReinitableConfigInterface;
1414

1515
$objectManager = Bootstrap::getObjectManager();
16+
/** @var Registry $registry */
17+
$registry = $objectManager->get(Registry::class);
18+
$registry->unregister('isSecureArea');
19+
$registry->register('isSecureArea', true);
20+
1621
//Deleting second website's store.
1722
$store = $objectManager->create(Store::class);
1823
if ($store->load('fixture_second_store', 'code')->getId()) {
1924
$store->delete();
2025
}
2126

2227
//Deleting the second website.
23-
/** @var Registry $registry */
24-
$registry = $objectManager->get(Registry::class);
25-
$registry->unregister('isSecureArea');
26-
$registry->register('isSecureArea', true);
2728

2829
$configResource = $objectManager->get(\Magento\Config\Model\ResourceModel\Config::class);
2930
//Restoring allowed countries.

0 commit comments

Comments
 (0)