Skip to content

Commit 22e6694

Browse files
committed
Merge branch 'MAGETWO-91626' into mpi-forwardport-0309
2 parents 9c95e80 + da5a19e commit 22e6694

28 files changed

+844
-227
lines changed

app/code/Magento/Customer/Model/Address/Validator/Country.php

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
use Magento\Customer\Model\Address\AbstractAddress;
99
use Magento\Customer\Model\Address\ValidatorInterface;
10-
use Magento\Framework\App\ObjectManager;
10+
use Magento\Directory\Helper\Data;
11+
use Magento\Directory\Model\AllowedCountries;
1112
use Magento\Store\Model\ScopeInterface;
1213

1314
/**
@@ -16,35 +17,25 @@
1617
class Country implements ValidatorInterface
1718
{
1819
/**
19-
* @var \Magento\Directory\Helper\Data
20+
* @var Data
2021
*/
2122
private $directoryData;
2223

2324
/**
24-
* @var \Magento\Directory\Model\AllowedCountries
25+
* @var AllowedCountries
2526
*/
2627
private $allowedCountriesReader;
2728

2829
/**
29-
* @var \Magento\Customer\Model\Config\Share
30-
*/
31-
private $shareConfig;
32-
33-
/**
34-
* @param \Magento\Directory\Helper\Data $directoryData
35-
* @param \Magento\Directory\Model\AllowedCountries|null $allowedCountriesReader
36-
* @param \Magento\Customer\Model\Config\Share|null $shareConfig
30+
* @param Data $directoryData
31+
* @param AllowedCountries $allowedCountriesReader
3732
*/
3833
public function __construct(
39-
\Magento\Directory\Helper\Data $directoryData,
40-
\Magento\Directory\Model\AllowedCountries $allowedCountriesReader = null,
41-
\Magento\Customer\Model\Config\Share $shareConfig = null
34+
Data $directoryData,
35+
AllowedCountries $allowedCountriesReader
4236
) {
4337
$this->directoryData = $directoryData;
44-
$this->allowedCountriesReader = $allowedCountriesReader
45-
?: ObjectManager::getInstance()->get(\Magento\Directory\Model\AllowedCountries::class);
46-
$this->shareConfig = $shareConfig
47-
?: ObjectManager::getInstance()->get(\Magento\Customer\Model\Config\Share::class);
38+
$this->allowedCountriesReader = $allowedCountriesReader;
4839
}
4940

5041
/**
@@ -128,12 +119,7 @@ private function validateRegion(AbstractAddress $address)
128119
*/
129120
private function getWebsiteAllowedCountries(AbstractAddress $address): array
130121
{
131-
$websiteId = null;
132-
133-
if (!$this->shareConfig->isGlobalScope()) {
134-
$websiteId = $address->getCustomer() ? $address->getCustomer()->getWebsiteId() : null;
135-
}
136-
137-
return $this->allowedCountriesReader->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE, $websiteId);
122+
$storeId = $address->getData('store_id');
123+
return $this->allowedCountriesReader->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId);
138124
}
139125
}

app/code/Magento/Customer/Model/ResourceModel/AddressRepository.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
namespace Magento\Customer\Model\ResourceModel;
99

10+
use Magento\Customer\Api\Data\AddressInterface;
1011
use Magento\Customer\Model\Address as CustomerAddressModel;
1112
use Magento\Customer\Model\Customer as CustomerModel;
1213
use Magento\Customer\Model\ResourceModel\Address\Collection;
@@ -123,6 +124,7 @@ public function save(\Magento\Customer\Api\Data\AddressInterface $address)
123124
} else {
124125
$addressModel->updateData($address);
125126
}
127+
$addressModel->setStoreId($customerModel->getStoreId());
126128

127129
$errors = $addressModel->validate();
128130
if ($errors !== true) {

app/code/Magento/Customer/Test/Unit/Model/Address/Validator/CountryTest.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ class CountryTest extends \PHPUnit\Framework\TestCase
2727
*/
2828
private $allowedCountriesReaderMock;
2929

30-
/**
31-
* @var \Magento\Customer\Model\Config\Share|\PHPUnit_Framework_MockObject_MockObject
32-
*/
33-
private $shareConfigMock;
34-
3530
protected function setUp()
3631
{
3732
$this->directoryDataMock = $this->createMock(\Magento\Directory\Helper\Data::class);
@@ -40,16 +35,11 @@ protected function setUp()
4035
\Magento\Directory\Model\AllowedCountries::class,
4136
['getAllowedCountries']
4237
);
43-
$this->shareConfigMock = $this->createPartialMock(
44-
\Magento\Customer\Model\Config\Share::class,
45-
['isGlobalScope']
46-
);
4738
$this->model = $this->objectManager->getObject(
4839
\Magento\Customer\Model\Address\Validator\Country::class,
4940
[
5041
'directoryData' => $this->directoryDataMock,
5142
'allowedCountriesReader' => $this->allowedCountriesReaderMock,
52-
'shareConfig' => $this->shareConfigMock,
5343
]
5444
);
5545
}
@@ -81,10 +71,9 @@ public function testValidate(array $data, array $countryIds, array $allowedRegio
8171
->method('isRegionRequired')
8272
->willReturn($data['regionRequired']);
8373

84-
$this->shareConfigMock->method('isGlobalScope')->willReturn(false);
8574
$this->allowedCountriesReaderMock
8675
->method('getAllowedCountries')
87-
->with(ScopeInterface::SCOPE_WEBSITE, null)
76+
->with(ScopeInterface::SCOPE_STORE, null)
8877
->willReturn($countryIds);
8978

9079
$addressMock->method('getCountryId')->willReturn($data['country_id']);

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)];

app/code/Magento/Sales/Block/Adminhtml/Order/Address/Form.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ protected function _prepareForm()
113113
$this->getUrl('sales/*/addressSave', ['address_id' => $this->_getAddress()->getId()])
114114
);
115115
$this->_form->setUseContainer(true);
116+
116117
return $this;
117118
}
118119

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public function getDataSelectorDisplay()
164164
public function getOrderDataJson()
165165
{
166166
$data = [];
167+
$this->_storeManager->setCurrentStore($this->getStoreId());
167168
if ($this->getCustomerId()) {
168169
$data['customer_id'] = $this->getCustomerId();
169170
$data['addresses'] = [];

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/Address.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public function __construct(
136136
$this->searchCriteriaBuilder = $criteriaBuilder;
137137
$this->filterBuilder = $filterBuilder;
138138
$this->addressMapper = $addressMapper;
139+
$this->backendQuoteSession = $sessionQuote;
139140
parent::__construct(
140141
$context,
141142
$sessionQuote,
@@ -217,6 +218,11 @@ public function getAddressCollectionJson()
217218
*/
218219
protected function _prepareForm()
219220
{
221+
$storeId = $this->getCreateOrderModel()
222+
->getSession()
223+
->getStoreId();
224+
$this->_storeManager->setCurrentStore($storeId);
225+
220226
$fieldset = $this->_form->addFieldset('main', ['no_container' => true]);
221227

222228
$addressForm = $this->_customerFormFactory->create('customer_address', 'adminhtml_customer_address');

0 commit comments

Comments
 (0)