Skip to content

Commit 548f012

Browse files
authored
ENGCOM-7664: magento/magento2#: GraphQl. setPaymentMethodAndPlaceOrder. Remove redundant logic. #28506
2 parents 3786d5a + 4cedeeb commit 548f012

File tree

3 files changed

+92
-3
lines changed

3 files changed

+92
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ public function __construct(
7171
*/
7272
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
7373
{
74-
if (!isset($args['input']['cart_id']) || empty($args['input']['cart_id'])) {
74+
if (empty($args['input']['cart_id'])) {
7575
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
7676
}
77-
$maskedCartId = $args['input']['cart_id'];
7877

79-
if (!isset($args['input']['payment_method']['code']) || empty($args['input']['payment_method']['code'])) {
78+
if (empty($args['input']['payment_method']['code'])) {
8079
throw new GraphQlInputException(__('Required parameter "code" for "payment_method" is missing.'));
8180
}
81+
82+
$maskedCartId = $args['input']['cart_id'];
8283
$paymentData = $args['input']['payment_method'];
8384

8485
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,50 @@ public function testSetDisabledPaymentOnCart()
281281
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
282282
}
283283

284+
/**
285+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
286+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
287+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
288+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
289+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
290+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
291+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
292+
*/
293+
public function testPlaceOrderWitMissingCartId()
294+
{
295+
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
296+
$maskedQuoteId = "";
297+
298+
$query = $this->getQuery($maskedQuoteId, $methodCode);
299+
300+
$this->expectExceptionMessage(
301+
"Required parameter \"cart_id\" is missing"
302+
);
303+
$this->graphQlMutation($query);
304+
}
305+
306+
/**
307+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
308+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
309+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
310+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
311+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
312+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
313+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
314+
*/
315+
public function testPlaceOrderWithMissingPaymentMethod()
316+
{
317+
$methodCode = "";
318+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
319+
320+
$query = $this->getQuery($maskedQuoteId, $methodCode);
321+
322+
$this->expectExceptionMessage(
323+
"Required parameter \"code\" for \"payment_method\" is missing."
324+
);
325+
$this->graphQlMutation($query);
326+
}
327+
284328
/**
285329
* @param string $maskedQuoteId
286330
* @param string $methodCode

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,50 @@ public function testSetDisabledPaymentOnCart()
218218
$this->graphQlMutation($query);
219219
}
220220

221+
/**
222+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
223+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
224+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
225+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
226+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
227+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
228+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
229+
*/
230+
public function testPlaceOrderWitMissingCartId()
231+
{
232+
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
233+
$maskedQuoteId = "";
234+
235+
$query = $this->getQuery($maskedQuoteId, $methodCode);
236+
237+
$this->expectExceptionMessage(
238+
"Required parameter \"cart_id\" is missing"
239+
);
240+
$this->graphQlMutation($query);
241+
}
242+
243+
/**
244+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
245+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
246+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
247+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
248+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
249+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
250+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
251+
*/
252+
public function testPlaceOrderWithMissingPaymentMethod()
253+
{
254+
$methodCode = "";
255+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
256+
257+
$query = $this->getQuery($maskedQuoteId, $methodCode);
258+
259+
$this->expectExceptionMessage(
260+
"Required parameter \"code\" for \"payment_method\" is missing."
261+
);
262+
$this->graphQlMutation($query);
263+
}
264+
221265
/**
222266
* @param string $maskedQuoteId
223267
* @param string $methodCode

0 commit comments

Comments
 (0)