Skip to content

Commit 6170993

Browse files
committed
Fixed setting billing address of wrong (another) customer
1 parent 5af7a1b commit 6170993

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Customer\Api\Data\AddressInterface;
1111
use Magento\CustomerGraphQl\Model\Customer\CheckCustomerAccount;
12+
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1213
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1314
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
1415
use Magento\Quote\Api\Data\CartInterface;
@@ -61,6 +62,16 @@ public function __construct(
6162

6263
/**
6364
* @inheritdoc
65+
* @param ContextInterface $context
66+
* @param CartInterface $cart
67+
* @param array $billingAddress
68+
* @throws GraphQlAuthorizationException
69+
* @throws GraphQlInputException
70+
* @throws \Magento\Framework\Exception\InputException
71+
* @throws \Magento\Framework\Exception\LocalizedException
72+
* @throws \Magento\Framework\Exception\NoSuchEntityException
73+
* @throws \Magento\Framework\GraphQl\Exception\GraphQlAuthenticationException
74+
* @throws \Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException
6475
*/
6576
public function execute(ContextInterface $context, CartInterface $cart, array $billingAddress): void
6677
{
@@ -91,6 +102,16 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b
91102

92103
/** @var AddressInterface $customerAddress */
93104
$customerAddress = $this->addressRepository->getById($customerAddressId);
105+
106+
if ((int)$customerAddress->getCustomerId() !== $context->getUserId()) {
107+
throw new GraphQlAuthorizationException(
108+
__(
109+
'The current user cannot use address with ID "%customer_address_id"',
110+
['customer_address_id' => $customerAddressId]
111+
)
112+
);
113+
}
114+
94115
$billingAddress = $this->addressModel->importCustomerAddressData($customerAddress);
95116
}
96117

0 commit comments

Comments
 (0)