Skip to content

Commit 955adf2

Browse files
committed
ACP2E-4223: Improved validation for rest api
1 parent 86ecde0 commit 955adf2

File tree

5 files changed

+4
-45
lines changed

5 files changed

+4
-45
lines changed

app/code/Magento/Checkout/Model/ShippingInformationManagement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public function saveAddressInformation(
213213

214214
$quote->setIsMultiShipping(false);
215215

216-
$this->quoteAddressValidationService->validateAddressesWithRules($quote, $address, $billingAddress);
216+
$this->quoteAddressValidationService->validateAddressesWithRules($address, $billingAddress);
217217

218218
$this->quoteRepository->save($quote);
219219
} catch (LocalizedException $e) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private function assignBillingAddress(AddressInterface $address, Quote $quote, b
130130
$quote->removeAddress($quote->getBillingAddress()->getId());
131131
$quote->setBillingAddress($address);
132132

133-
$this->quoteAddressValidationService->validateAddressesWithRules($quote, null, $address);
133+
$this->quoteAddressValidationService->validateAddressesWithRules(null, $address);
134134

135135
try {
136136
$this->getShippingAddressAssignment()->setAddress($quote, $address, $useForShipping);

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

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ public function __construct(
4949
* @param AddressInterface|null $billingAddress
5050
* @return void
5151
* @throws InputException
52-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5352
*/
5453
public function validateAddressesWithRules(
55-
Quote $quote,
5654
?AddressInterface $shippingAddress = null,
5755
?AddressInterface $billingAddress = null
5856
): void {
@@ -108,45 +106,6 @@ private function validateSingleAddress(?AddressInterface $address, string $addre
108106
return true;
109107
}
110108

111-
/**
112-
* Validate shipping addresses using validation rules
113-
*
114-
* @param Quote $quote
115-
* @return void
116-
* @throws InputException
117-
*/
118-
public function validateShippingAddressWithRules(Quote $quote): void
119-
{
120-
$shippingAddress = $quote->getShippingAddress();
121-
122-
if ($shippingAddress) {
123-
$this->addressAttributeValidator->validate($shippingAddress, 'shipping');
124-
}
125-
}
126-
127-
/**
128-
* Validate billing addresses using validation rules
129-
*
130-
* @param Quote $quote
131-
* @return void
132-
* @throws InputException
133-
*/
134-
public function validateBillingAddressWithRules(Quote $quote): void
135-
{
136-
$billingAddress = $quote->getBillingAddress();
137-
$shippingAddress = $quote->getShippingAddress();
138-
139-
if (!$billingAddress) {
140-
return;
141-
}
142-
143-
if ($shippingAddress && $this->addressComparator->isEqual($billingAddress, $shippingAddress)) {
144-
return;
145-
}
146-
147-
$this->addressAttributeValidator->validate($billingAddress, 'billing');
148-
}
149-
150109
/**
151110
* Check if address has any data for validation
152111
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $addres
125125
$address->setSaveInAddressBook($saveInAddressBook);
126126
$address->setCollectShippingRates(true);
127127

128-
$this->quoteAddressValidationService->validateAddressesWithRules($quote, $address, null);
128+
$this->quoteAddressValidationService->validateAddressesWithRules($address, null);
129129

130130
try {
131131
$address->save();

app/code/Magento/Quote/Test/Unit/Model/ShippingAddressManagementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function testAssign(bool $saveInAddressBook, bool $showCompany): void
160160
$this->quoteAddressValidationServiceMock
161161
->expects($this->once())
162162
->method('validateAddressesWithRules')
163-
->with($this->quoteMock, $addressMock, null);
163+
->with($addressMock, null);
164164
$this->model->assign($cartId, $addressMock);
165165
}
166166

0 commit comments

Comments
 (0)