Skip to content

Commit e9a701f

Browse files
committed
magento/graphql-ce#961: ShippingAddressInput.postcode: String, is not required by Schema
1 parent 2555933 commit e9a701f

File tree

3 files changed

+29
-39
lines changed

3 files changed

+29
-39
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/SetBillingAddressOnCart.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,15 @@ private function createBillingAddress(
129129
(int)$context->getUserId()
130130
);
131131
}
132+
$errors = $billingAddress->validate();
132133

133-
134-
$this->validateAddress($billingAddress);
134+
if (true !== $errors) {
135+
$e = new GraphQlInputException(__('Billing address errors'));
136+
foreach ($errors as $error){
137+
$e->addError(new GraphQlInputException($error));
138+
}
139+
throw $e;
140+
}
135141

136142
return $billingAddress;
137143
}

app/code/Magento/QuoteGraphQl/Model/Cart/SetShippingAddressesOnCart.php

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -53,46 +53,14 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
5353

5454
$shippingAddress = $this->getShippingAddress->execute($context, $shippingAddressInput);
5555

56-
$this->validateAddress($shippingAddress);
57-
58-
$this->assignShippingAddressToCart->execute($cart, $shippingAddress);
59-
}
60-
61-
/**
62-
* Validate quote address.
63-
*
64-
* @param Address $shippingAddress
65-
*
66-
* @throws GraphQlInputException
67-
*/
68-
private function validateAddress(Address $shippingAddress)
69-
{
7056
$errors = $shippingAddress->validate();
7157

7258
if (true !== $errors) {
73-
throw new GraphQlInputException(
74-
__('Shipping address error: %message', ['message' => $this->getAddressErrors($errors)])
75-
);
59+
$e = new GraphQlInputException(__('Shipping address error'));
60+
foreach ($errors as $error){
61+
$e->addError(new GraphQlInputException($error));
62+
}
63+
throw $e;
7664
}
7765
}
78-
79-
/**
80-
* Collecting errors.
81-
*
82-
* @param array $errors
83-
* @return string
84-
*
85-
* @todo change implementation in https://github.com/magento/graphql-ce/issues/970.
86-
*/
87-
private function getAddressErrors(array $errors): string
88-
{
89-
$errorMessages = [];
90-
91-
/** @var \Magento\Framework\Phrase $error */
92-
foreach ($errors as $error) {
93-
$errorMessages[] = $error->render();
94-
}
95-
96-
return implode(PHP_EOL, $errorMessages);
97-
}
9866
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,22 @@ public function dataProviderSetWithoutRequiredParameters(): array
658658
}',
659659
'"regionId" is required. Enter and try again.'
660660
],
661+
'missed_multiple_fields' => [
662+
'cart_id: "cart_id_value"
663+
billing_address: {
664+
address: {
665+
firstname: "test firstname"
666+
lastname: "test lastname"
667+
company: "test company"
668+
street: ["test street 1", "test street 2"]
669+
city: "test city"
670+
country_code: "US"
671+
telephone: "88776655"
672+
}
673+
}',
674+
'"postcode" is required. Enter and try again.
675+
"regionId" is required. Enter and try again.'
676+
]
661677
];
662678
}
663679

0 commit comments

Comments
 (0)