Skip to content

Commit babb02e

Browse files
committed
ACP2E-4156: For Shipping Information Server Side Validation is not Working using REST API
1 parent 8a5c57e commit babb02e

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

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

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,7 @@ private function validateAddressAttributes(AddressInterface $address, string $ad
107107
}
108108
$validator = $this->validatorFactory->createValidator('customer_address', 'save');
109109
if (!$validator->isValid($customerAddress)) {
110-
$errorMessages = [];
111-
$messages = $validator->getMessages();
112-
foreach ($messages as $message) {
113-
if (is_array($message)) {
114-
foreach ($message as $msg) {
115-
$errorMessages[] = $msg;
116-
}
117-
} else {
118-
$errorMessages[] = $message;
119-
}
120-
}
121-
throw new InputException(
122-
__(
123-
'The %1 address contains invalid data: %2',
124-
$addressType,
125-
implode(', ', $errorMessages)
126-
)
127-
);
110+
$this->throwValidationException($validator->getMessages(), $addressType);
128111
}
129112
} catch (LocalizedException $e) {
130113
throw new InputException(__($e->getMessage()));
@@ -161,4 +144,33 @@ private function createCustomerAddressFromQuoteAddress(
161144

162145
return $customerAddress;
163146
}
147+
148+
/**
149+
* Process validator messages and throw validation exception
150+
*
151+
* @param array $messages
152+
* @param string $addressType
153+
* @return void
154+
* @throws InputException
155+
*/
156+
private function throwValidationException(array $messages, string $addressType): void
157+
{
158+
$errorMessages = [];
159+
foreach ($messages as $message) {
160+
if (is_array($message)) {
161+
foreach ($message as $msg) {
162+
$errorMessages[] = $msg;
163+
}
164+
} else {
165+
$errorMessages[] = $message;
166+
}
167+
}
168+
throw new InputException(
169+
__(
170+
'The %1 address contains invalid data: %2',
171+
$addressType,
172+
implode(', ', $errorMessages)
173+
)
174+
);
175+
}
164176
}

0 commit comments

Comments
 (0)