Skip to content

Commit

Permalink
magento#961: ShippingAddressInput.postcode: String, is not required b…
Browse files Browse the repository at this point in the history
…y Schema
  • Loading branch information
lenaorobei committed Oct 23, 2019
1 parent 2555933 commit e9a701f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,15 @@ private function createBillingAddress(
(int)$context->getUserId()
);
}
$errors = $billingAddress->validate();


$this->validateAddress($billingAddress);
if (true !== $errors) {
$e = new GraphQlInputException(__('Billing address errors'));
foreach ($errors as $error){
$e->addError(new GraphQlInputException($error));
}
throw $e;
}

return $billingAddress;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,46 +53,14 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s

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

$this->validateAddress($shippingAddress);

$this->assignShippingAddressToCart->execute($cart, $shippingAddress);
}

/**
* Validate quote address.
*
* @param Address $shippingAddress
*
* @throws GraphQlInputException
*/
private function validateAddress(Address $shippingAddress)
{
$errors = $shippingAddress->validate();

if (true !== $errors) {
throw new GraphQlInputException(
__('Shipping address error: %message', ['message' => $this->getAddressErrors($errors)])
);
$e = new GraphQlInputException(__('Shipping address error'));
foreach ($errors as $error){
$e->addError(new GraphQlInputException($error));
}
throw $e;
}
}

/**
* Collecting errors.
*
* @param array $errors
* @return string
*
* @todo change implementation in https://github.com/magento/graphql-ce/issues/970.
*/
private function getAddressErrors(array $errors): string
{
$errorMessages = [];

/** @var \Magento\Framework\Phrase $error */
foreach ($errors as $error) {
$errorMessages[] = $error->render();
}

return implode(PHP_EOL, $errorMessages);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,22 @@ public function dataProviderSetWithoutRequiredParameters(): array
}',
'"regionId" is required. Enter and try again.'
],
'missed_multiple_fields' => [
'cart_id: "cart_id_value"
billing_address: {
address: {
firstname: "test firstname"
lastname: "test lastname"
company: "test company"
street: ["test street 1", "test street 2"]
city: "test city"
country_code: "US"
telephone: "88776655"
}
}',
'"postcode" is required. Enter and try again.
"regionId" is required. Enter and try again.'
]
];
}

Expand Down

0 comments on commit e9a701f

Please sign in to comment.