Skip to content

Commit 30829e4

Browse files
committed
magento/graphql-ce#486: Add customer account validation in Quote operations
1 parent efd8480 commit 30829e4

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8282
}
8383
$maskedCartId = $args['input']['cart_id'];
8484

85-
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId());
86-
$this->checkCartCheckoutAllowance->execute($cart);
87-
8885
if (!isset($args['input']['payment_method']['code']) || empty($args['input']['payment_method']['code'])) {
8986
throw new GraphQlInputException(__('Required parameter "code" for "payment_method" is missing.'));
9087
}
9188
$paymentMethodCode = $args['input']['payment_method']['code'];
9289

90+
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId());
91+
$this->checkCartCheckoutAllowance->execute($cart);
92+
9393
$poNumber = $args['input']['payment_method']['purchase_order_number'] ?? null;
9494
$additionalData = $this->additionalDataProviderPool->getData($paymentMethodCode, $args) ?? [];
9595

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ public function testSetPaymentMethodToAnotherCustomerCart()
187187
*/
188188
public function testSetPaymentMethodWithoutRequiredParameters(string $input, string $message)
189189
{
190+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
191+
$input = str_replace('cart_id_value', $maskedQuoteId, $input);
192+
190193
$query = <<<QUERY
191194
mutation {
192195
setPaymentMethodOnCart(
@@ -235,11 +238,11 @@ public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array
235238
'Required parameter "cart_id" is missing.'
236239
],
237240
'missed_payment_method' => [
238-
'cart_id: "test_quote"',
241+
'cart_id: "cart_id_value"',
239242
'Required parameter "code" for "payment_method" is missing.'
240243
],
241244
'missed_payment_method_code' => [
242-
'cart_id: "test_quote", payment_method: {code: ""}',
245+
'cart_id: "cart_id_value", payment_method: {code: ""}',
243246
'Required parameter "code" for "payment_method" is missing.'
244247
],
245248
];

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetPaymentMethodOnCartTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ public function testSetPaymentMethodToCustomerCart()
155155
*/
156156
public function testSetPaymentMethodWithoutRequiredParameters(string $input, string $message)
157157
{
158+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
159+
$input = str_replace('cart_id_value', $maskedQuoteId, $input);
160+
158161
$query = <<<QUERY
159162
mutation {
160163
setPaymentMethodOnCart(
@@ -185,11 +188,11 @@ public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array
185188
'Required parameter "cart_id" is missing.'
186189
],
187190
'missed_payment_method' => [
188-
'cart_id: "test_quote"',
191+
'cart_id: "cart_id_value"',
189192
'Required parameter "code" for "payment_method" is missing.'
190193
],
191194
'missed_payment_method_code' => [
192-
'cart_id: "test_quote", payment_method: {code: ""}',
195+
'cart_id: "cart_id_value", payment_method: {code: ""}',
193196
'Required parameter "code" for "payment_method" is missing.'
194197
],
195198
];

0 commit comments

Comments
 (0)