Skip to content

Commit 9a0ecef

Browse files
committed
Merge branch '2.3-develop-graphql-PR-yogesh-5' into 542-new-fixture-for-SetOfflineShippingMethodsOnCartTest
2 parents 7b80d61 + 829a39b commit 9a0ecef

16 files changed

+577
-118
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
namespace Magento\QuoteGraphQl\Model\Cart;
99

1010
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
11-
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1211
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1312
use Magento\Quote\Api\Data\AddressInterface;
1413
use Magento\Quote\Api\Data\AddressInterfaceFactory;
14+
use Magento\Quote\Api\Data\CartInterface;
1515
use Magento\Quote\Model\ResourceModel\Quote\Address as AddressResource;
1616

1717
/**
@@ -44,14 +44,14 @@ public function __construct(
4444
/**
4545
* Get quote address
4646
*
47+
* @param CartInterface $cart
4748
* @param int $quoteAddressId
4849
* @param int|null $customerId
4950
* @return AddressInterface
50-
* @throws GraphQlInputException
51-
* @throws GraphQlNoSuchEntityException
5251
* @throws GraphQlAuthorizationException
52+
* @throws GraphQlNoSuchEntityException
5353
*/
54-
public function execute(int $quoteAddressId, ?int $customerId): AddressInterface
54+
public function execute(CartInterface $cart, int $quoteAddressId, ?int $customerId): AddressInterface
5555
{
5656
$quoteAddress = $this->quoteAddressFactory->create();
5757

@@ -62,14 +62,15 @@ public function execute(int $quoteAddressId, ?int $customerId): AddressInterface
6262
);
6363
}
6464

65-
$quoteAddressCustomerId = (int)$quoteAddress->getCustomerId();
66-
67-
/* Guest cart, allow operations */
68-
if (!$quoteAddressCustomerId && null === $customerId) {
69-
return $quoteAddress;
65+
// TODO: GetQuoteAddress::execute should depend only on AddressInterface contract
66+
// https://github.com/magento/graphql-ce/issues/550
67+
if ($quoteAddress->getQuoteId() !== $cart->getId()) {
68+
throw new GraphQlNoSuchEntityException(
69+
__('Cart does not contain address with ID "%cart_address_id"', ['cart_address_id' => $quoteAddressId])
70+
);
7071
}
7172

72-
if ($quoteAddressCustomerId !== $customerId) {
73+
if ((int)$quoteAddress->getCustomerId() !== (int)$customerId) {
7374
throw new GraphQlAuthorizationException(
7475
__(
7576
'The current user cannot use cart address with ID "%cart_address_id"',

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
6969
}
7070
$methodCode = $shippingMethodInput['method_code'];
7171

72-
$quoteAddress = $this->getQuoteAddress->execute($cartAddressId, $context->getUserId());
73-
72+
$quoteAddress = $this->getQuoteAddress->execute($cart, $cartAddressId, $context->getUserId());
7473
$this->assignShippingMethodToCart->execute($cart, $quoteAddress, $carrierCode, $methodCode);
7574
}
7675
}

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,17 +429,27 @@ public function testSetBillingAddressIfCustomerIsNotOwnerOfAddress()
429429

430430
/**
431431
* @magentoApiDataFixture Magento/Customer/_files/customer.php
432+
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
432433
* @expectedException \Exception
433434
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
434435
*/
435436
public function testSetBillingAddressOnNonExistentCart()
436437
{
437438
$maskedQuoteId = 'non_existent_masked_id';
438439
$query = <<<QUERY
439-
{
440-
cart(cart_id: "$maskedQuoteId") {
441-
items {
442-
id
440+
mutation {
441+
setBillingAddressOnCart(
442+
input: {
443+
cart_id: "$maskedQuoteId"
444+
billing_address: {
445+
customer_address_id: 1
446+
}
447+
}
448+
) {
449+
cart {
450+
billing_address {
451+
city
452+
}
443453
}
444454
}
445455
}

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,9 @@ public function testSetNonExistentPaymentMethod()
126126
public function testSetPaymentOnNonExistentCart()
127127
{
128128
$maskedQuoteId = 'non_existent_masked_id';
129-
$query = <<<QUERY
130-
{
131-
cart(cart_id: "$maskedQuoteId") {
132-
items {
133-
id
134-
}
135-
}
136-
}
137-
QUERY;
129+
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
130+
131+
$query = $this->getQuery($maskedQuoteId, $methodCode);
138132
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
139133
}
140134

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\GraphQl\Quote;
99

10+
use Magento\Framework\Exception\NoSuchEntityException;
1011
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
1112
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1213
use Magento\Quote\Model\QuoteFactory;
@@ -51,7 +52,7 @@ public function __construct(
5152
*
5253
* @param string $reversedOrderId
5354
* @return string
54-
* @throws \Magento\Framework\Exception\NoSuchEntityException
55+
* @throws NoSuchEntityException
5556
*/
5657
public function execute(string $reversedOrderId): string
5758
{
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Quote;
9+
10+
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
11+
use Magento\Quote\Model\QuoteFactory;
12+
13+
/**
14+
* Get quote shipping address id by reserved order id
15+
*/
16+
class GetQuoteShippingAddressIdByReservedQuoteId
17+
{
18+
/**
19+
* @var QuoteFactory
20+
*/
21+
private $quoteFactory;
22+
23+
/**
24+
* @var QuoteResource
25+
*/
26+
private $quoteResource;
27+
28+
/**
29+
* @param QuoteFactory $quoteFactory
30+
* @param QuoteResource $quoteResource
31+
*/
32+
public function __construct(
33+
QuoteFactory $quoteFactory,
34+
QuoteResource $quoteResource
35+
) {
36+
$this->quoteFactory = $quoteFactory;
37+
$this->quoteResource = $quoteResource;
38+
}
39+
40+
/**
41+
* Get quote shipping address id by reserved order id
42+
*
43+
* @param string $reversedOrderId
44+
* @return int
45+
*/
46+
public function execute(string $reversedOrderId): int
47+
{
48+
$quote = $this->quoteFactory->create();
49+
$this->quoteResource->load($quote, $reversedOrderId, 'reserved_order_id');
50+
51+
return (int)$quote->getShippingAddress()->getId();
52+
}
53+
}

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,30 @@ public function testSetBillingAddressOnNonExistentCart()
248248
{
249249
$maskedQuoteId = 'non_existent_masked_id';
250250
$query = <<<QUERY
251-
{
252-
cart(cart_id: "$maskedQuoteId") {
253-
items {
254-
id
251+
mutation {
252+
setBillingAddressOnCart(
253+
input: {
254+
cart_id: "$maskedQuoteId"
255+
billing_address: {
256+
address: {
257+
firstname: "test firstname"
258+
lastname: "test lastname"
259+
company: "test company"
260+
street: ["test street 1", "test street 2"]
261+
city: "test city"
262+
region: "test region"
263+
postcode: "887766"
264+
country_code: "US"
265+
telephone: "88776655"
266+
save_in_address_book: false
267+
}
268+
}
269+
}
270+
) {
271+
cart {
272+
billing_address {
273+
city
274+
}
255275
}
256276
}
257277
}
@@ -289,7 +309,6 @@ public function testSetBillingAddressWithoutRequiredParameters(string $input, st
289309
}
290310
}
291311
QUERY;
292-
293312
$this->expectExceptionMessage($message);
294313
$this->graphQlQuery($query);
295314
}

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,9 @@ public function testSetNonExistentPaymentMethod()
113113
public function testSetPaymentOnNonExistentCart()
114114
{
115115
$maskedQuoteId = 'non_existent_masked_id';
116-
$query = <<<QUERY
117-
{
118-
cart(cart_id: "$maskedQuoteId") {
119-
items {
120-
id
121-
}
122-
}
123-
}
124-
QUERY;
116+
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
117+
118+
$query = $this->getQuery($maskedQuoteId, $methodCode);
125119
$this->graphQlQuery($query);
126120
}
127121

0 commit comments

Comments
 (0)