Skip to content

Commit 57ee757

Browse files
committed
ACP2E-4156: For Shipping Information Server Side Validation is not Working using REST API
1 parent 5e4c2ad commit 57ee757

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

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

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function __construct(
5555

5656
/**
5757
* @inheritDoc
58+
*
5859
* @throws InputException
5960
*/
6061
public function saveAddressInformation(
@@ -94,22 +95,7 @@ public function saveAddressInformation(
9495
private function validateAddressAttributes(AddressInterface $address, string $addressType): void
9596
{
9697
try {
97-
$customerAddress = $this->addressFactory->create();
98-
$customerAddress->setData([
99-
'firstname' => $address->getFirstname(),
100-
'lastname' => $address->getLastname(),
101-
'street' => $address->getStreet(),
102-
'city' => $address->getCity(),
103-
'region' => $address->getRegion(),
104-
'region_id' => $address->getRegionId(),
105-
'region_code' => $address->getRegionCode(),
106-
'postcode' => $address->getPostcode(),
107-
'country_id' => $address->getCountryId(),
108-
'telephone' => $address->getTelephone(),
109-
'company' => $address->getCompany(),
110-
'email' => $address->getEmail(),
111-
'address_type' => $addressType
112-
]);
98+
$customerAddress = $this->createCustomerAddressFromQuoteAddress($address, $addressType);
11399
$extensionAttributes = $address->getExtensionAttributes();
114100
if ($extensionAttributes) {
115101
$extensionAttributesData = $extensionAttributes->__toArray();
@@ -144,4 +130,36 @@ private function validateAddressAttributes(AddressInterface $address, string $ad
144130
throw new InputException(__($e->getMessage()));
145131
}
146132
}
133+
134+
/**
135+
* Create customer address object from quote address
136+
*
137+
* @param AddressInterface $address
138+
* @param string $addressType
139+
* @return \Magento\Customer\Model\Address
140+
*/
141+
private function createCustomerAddressFromQuoteAddress(
142+
AddressInterface $address,
143+
string $addressType
144+
): \Magento\Customer\Model\Address
145+
{
146+
$customerAddress = $this->addressFactory->create();
147+
$customerAddress->setData([
148+
'firstname' => $address->getFirstname(),
149+
'lastname' => $address->getLastname(),
150+
'street' => $address->getStreet(),
151+
'city' => $address->getCity(),
152+
'region' => $address->getRegion(),
153+
'region_id' => $address->getRegionId(),
154+
'region_code' => $address->getRegionCode(),
155+
'postcode' => $address->getPostcode(),
156+
'country_id' => $address->getCountryId(),
157+
'telephone' => $address->getTelephone(),
158+
'company' => $address->getCompany(),
159+
'email' => $address->getEmail(),
160+
'address_type' => $addressType
161+
]);
162+
163+
return $customerAddress;
164+
}
147165
}

dev/tests/api-functional/testsuite/Magento/Checkout/Api/GuestShippingInformationManagementValidationTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,10 @@ private function getMaskedCartId(string $reservedOrderId): string
295295
* @param ShippingInformationInterface $shippingInformation
296296
* @return array
297297
*/
298-
private function callSaveAddressInformation(string $cartId, ShippingInformationInterface $shippingInformation): array
298+
private function callSaveAddressInformation(
299+
string $cartId,
300+
ShippingInformationInterface $shippingInformation
301+
): array
299302
{
300303
$serviceInfo = [
301304
'rest' => [

0 commit comments

Comments
 (0)