Skip to content

Commit be027d8

Browse files
committed
Add extension point for Quote Address.
Move logic related to Shipping Address to the GetShippingAddress service.
1 parent 0402368 commit be027d8

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,36 @@ public function __construct(QuoteAddressFactory $quoteAddressFactory)
3232
}
3333

3434
/**
35+
* Get Shipping Address based on the input.
36+
*
3537
* @param ContextInterface $context
3638
* @param array $shippingAddressInput
3739
* @return Address
3840
* @throws GraphQlAuthorizationException
3941
* @throws GraphQlInputException
4042
* @throws GraphQlNoSuchEntityException
4143
*/
42-
public function execute(ContextInterface $context, array $shippingAddressInput)
44+
public function execute(ContextInterface $context, array $shippingAddressInput): Address
4345
{
4446
$customerAddressId = $shippingAddressInput['customer_address_id'] ?? null;
47+
$addressInput = $shippingAddressInput['address'] ?? null;
4548

46-
$addressInput = $shippingAddressInput['address'];
4749
if ($addressInput) {
4850
$addressInput['customer_notes'] = $shippingAddressInput['customer_notes'] ?? '';
4951
}
5052

53+
if (null === $customerAddressId && null === $addressInput) {
54+
throw new GraphQlInputException(
55+
__('The shipping address must contain either "customer_address_id" or "address".')
56+
);
57+
}
58+
59+
if ($customerAddressId && $addressInput) {
60+
throw new GraphQlInputException(
61+
__('The shipping address cannot contain "customer_address_id" and "address" at the same time.')
62+
);
63+
}
64+
5165
if (null === $customerAddressId) {
5266
$shippingAddress = $this->quoteAddressFactory->createBasedOnInputData($addressInput);
5367
} else {

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,6 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
4949
);
5050
}
5151
$shippingAddressInput = current($shippingAddressesInput);
52-
$customerAddressId = $shippingAddressInput['customer_address_id'] ?? null;
53-
$addressInput = $shippingAddressInput['address'] ?? null;
54-
55-
if (null === $customerAddressId && null === $addressInput) {
56-
throw new GraphQlInputException(
57-
__('The shipping address must contain either "customer_address_id" or "address".')
58-
);
59-
}
60-
61-
if ($customerAddressId && $addressInput) {
62-
throw new GraphQlInputException(
63-
__('The shipping address cannot contain "customer_address_id" and "address" at the same time.')
64-
);
65-
}
6652

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

0 commit comments

Comments
 (0)