Skip to content

Commit 0b36aac

Browse files
author
Mariana Lashch
committed
Merge branch 'MAGETWO-90496' into mpi-PR-0207
2 parents dac113d + c23480a commit 0b36aac

File tree

23 files changed

+906
-363
lines changed

23 files changed

+906
-363
lines changed

app/code/Magento/Customer/Model/Address/AbstractAddress.php

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
use Magento\Customer\Api\Data\RegionInterfaceFactory;
1414
use Magento\Customer\Model\Data\Address as AddressData;
1515
use Magento\Framework\Model\AbstractExtensibleModel;
16-
use Magento\Framework\App\ObjectManager;
17-
use Magento\Store\Model\ScopeInterface;
1816

1917
/**
2018
* Address abstract model
@@ -121,16 +119,6 @@ class AbstractAddress extends AbstractExtensibleModel implements AddressModelInt
121119
*/
122120
protected $dataObjectHelper;
123121

124-
/**
125-
* @var \Magento\Directory\Model\AllowedCountries
126-
*/
127-
private $allowedCountriesReader;
128-
129-
/**
130-
* @var \Magento\Customer\Model\Config\Share
131-
*/
132-
private $shareConfig;
133-
134122
/**
135123
* @param \Magento\Framework\Model\Context $context
136124
* @param \Magento\Framework\Registry $registry
@@ -166,9 +154,7 @@ public function __construct(
166154
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
167155
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
168156
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
169-
array $data = [],
170-
\Magento\Directory\Model\AllowedCountries $allowedCountriesReader = null,
171-
\Magento\Customer\Model\Config\Share $shareConfig = null
157+
array $data = []
172158
) {
173159
$this->_directoryData = $directoryData;
174160
$data = $this->_implodeArrayField($data);
@@ -180,10 +166,6 @@ public function __construct(
180166
$this->addressDataFactory = $addressDataFactory;
181167
$this->regionDataFactory = $regionDataFactory;
182168
$this->dataObjectHelper = $dataObjectHelper;
183-
$this->allowedCountriesReader = $allowedCountriesReader
184-
?: ObjectManager::getInstance()->get(\Magento\Directory\Model\AllowedCountries::class);
185-
$this->shareConfig = $shareConfig
186-
?: ObjectManager::getInstance()->get(\Magento\Customer\Model\Config\Share::class);
187169
parent::__construct(
188170
$context,
189171
$registry,
@@ -641,7 +623,8 @@ public function validate()
641623
$errors[] = __('%fieldName is a required field.', ['fieldName' => 'countryId']);
642624
} else {
643625
//Checking if such country exists.
644-
if (!in_array($countryId, $this->getWebsiteAllowedCountries(), true)) {
626+
$countryCollection = $this->_directoryData->getCountryCollection($this->getStoreId());
627+
if (!in_array($countryId, $countryCollection->getAllIds(), true)) {
645628
$errors[] = __(
646629
'Invalid value of "%value" provided for the %fieldName field.',
647630
[
@@ -685,22 +668,6 @@ public function validate()
685668
return $errors;
686669
}
687670

688-
/**
689-
* Return allowed counties per website.
690-
*
691-
* @return array
692-
*/
693-
private function getWebsiteAllowedCountries(): array
694-
{
695-
$websiteId = null;
696-
697-
if (!$this->shareConfig->isGlobalScope()) {
698-
$websiteId = $this->getCustomer() ? $this->getCustomer()->getWebsiteId() : null;
699-
}
700-
701-
return $this->allowedCountriesReader->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE, $websiteId);
702-
}
703-
704671
/**
705672
* @return \Magento\Directory\Model\Region
706673
*/

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/AbstractAddressTest.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ class AbstractAddressTest extends \PHPUnit\Framework\TestCase
4040
/** @var \Magento\Framework\Data\Collection\AbstractDb|\PHPUnit_Framework_MockObject_MockObject */
4141
protected $resourceCollectionMock;
4242

43-
/**
44-
* @var \Magento\Directory\Model\AllowedCountries|\PHPUnit_Framework_MockObject_MockObject
45-
*/
46-
private $allowedCountriesReaderMock;
47-
48-
/**
49-
* @var \Magento\Customer\Model\Config\Share|\PHPUnit_Framework_MockObject_MockObject
50-
*/
51-
private $shareConfigMock;
52-
5343
/** @var \Magento\Customer\Model\Address\AbstractAddress */
5444
protected $model;
5545

@@ -105,9 +95,7 @@ protected function setUp()
10595
'regionFactory' => $this->regionFactoryMock,
10696
'countryFactory' => $this->countryFactoryMock,
10797
'resource' => $this->resourceMock,
108-
'resourceCollection' => $this->resourceCollectionMock,
109-
'allowedCountriesReader' => $this->allowedCountriesReaderMock,
110-
'shareConfig' => $this->shareConfigMock,
98+
'resourceCollection' => $this->resourceCollectionMock
11199
]
112100
);
113101
}
@@ -325,10 +313,15 @@ public function testValidate(array $data, $expected)
325313
$this->directoryDataMock->expects($this->any())
326314
->method('isRegionRequired');
327315

328-
$this->shareConfigMock->method('isGlobalScope')->willReturn(false);
329-
$this->allowedCountriesReaderMock
330-
->method('getAllowedCountries')
331-
->with(ScopeInterface::SCOPE_WEBSITE, null)
316+
$countryCollectionMock = $this->getMockBuilder(\Magento\Directory\Model\ResourceModel\Country\Collection::class)
317+
->disableOriginalConstructor()
318+
->setMethods(['getAllIds'])
319+
->getMock();
320+
321+
$this->directoryDataMock->method('getCountryCollection')
322+
->willReturn($countryCollectionMock);
323+
324+
$countryCollectionMock->method('getAllIds')
332325
->willReturn([$countryId]);
333326

334327
$regionModelMock = $this->getMockBuilder(\Magento\Directory\Model\Region::class)

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Directory\Model\AllowedCountries;
1212
use Magento\Framework\App\ObjectManager;
1313
use Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage as OrderAmountValidationMessage;
14+
use \Magento\Store\Model\ScopeInterface;
1415

1516
/**
1617
* @api
@@ -75,32 +76,36 @@ public function validateQuoteAmount(QuoteEntity $quote, $amount)
7576
public function validateBeforeSubmit(QuoteEntity $quote)
7677
{
7778
if (!$quote->isVirtual()) {
78-
if ($quote->getShippingAddress()->validate() !== true) {
79+
$address = $quote->getShippingAddress();
80+
$address->setStoreId($quote->getStoreId());
81+
if ($address->validate() !== true) {
7982
throw new \Magento\Framework\Exception\LocalizedException(
8083
__(
8184
'Please check the shipping address information. %1',
82-
implode(' ', $quote->getShippingAddress()->validate())
85+
implode(' ', $address->validate())
8386
)
8487
);
8588
}
8689

8790
// Checks if country id present in the allowed countries list.
8891
if (!in_array(
89-
$quote->getShippingAddress()->getCountryId(),
90-
$this->allowedCountryReader->getAllowedCountries()
92+
$address->getCountryId(),
93+
$this->allowedCountryReader->getAllowedCountries(ScopeInterface::SCOPE_STORE, $quote->getStoreId())
9194
)) {
9295
throw new \Magento\Framework\Exception\LocalizedException(
9396
__('Some addresses cannot be used due to country-specific configurations.')
9497
);
9598
}
9699

97-
$method = $quote->getShippingAddress()->getShippingMethod();
98-
$rate = $quote->getShippingAddress()->getShippingRateByCode($method);
100+
$method = $address->getShippingMethod();
101+
$rate = $address->getShippingRateByCode($method);
99102
if (!$method || !$rate) {
100103
throw new \Magento\Framework\Exception\LocalizedException(__('Please specify a shipping method.'));
101104
}
102105
}
103-
if ($quote->getBillingAddress()->validate() !== true) {
106+
$billingAddress = $quote->getBillingAddress();
107+
$billingAddress->setStoreId($quote->getStoreId());
108+
if ($billingAddress->validate() !== true) {
104109
throw new \Magento\Framework\Exception\LocalizedException(
105110
__(
106111
'Please check the billing address information. %1',

0 commit comments

Comments
 (0)