Skip to content

Commit e1edbdf

Browse files
committed
MC-22215: Add customerCart Query and cart_id changes to schema and related resolvers
- Added customerQuery changes added from review comments
1 parent 88b1228 commit e1edbdf

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

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

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

1010
use Magento\Framework\Exception\NoSuchEntityException;
1111
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1213
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1314
use Magento\Framework\GraphQl\Query\ResolverInterface;
1415
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
@@ -62,9 +63,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6263
}
6364

6465
} else {
65-
throw new LocalizedException(
66-
__('User cannot access the cart unless loggedIn and with a valid customer token')
67-
);
66+
throw new GraphQlInputException(__('The request is allowed for logged in customer'));
6867
}
6968

7069
return [

app/code/Magento/QuoteGraphQl/Model/Resolver/CartId.php renamed to app/code/Magento/QuoteGraphQl/Model/Resolver/MaskedCartId.php

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

1010
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\Exception\NoSuchEntityException;
1112
use Magento\Framework\GraphQl\Config\Element\Field;
13+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1214
use Magento\Framework\GraphQl\Query\ResolverInterface;
1315
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1416
use Magento\Quote\Model\Quote;
@@ -19,10 +21,11 @@
1921
/**
2022
* Get cart id from the cart
2123
*/
22-
class CartId implements ResolverInterface
24+
class MaskedCartId implements ResolverInterface
2325
{
2426
/**
2527
* @var QuoteIdMaskFactory
28+
*
2629
*/
2730
private $quoteIdMaskFactory;
2831

@@ -71,20 +74,15 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7174
*
7275
* @param int $quoteId
7376
* @return string
74-
* @throws \Magento\Framework\Exception\AlreadyExistsException
7577
* @throws \Magento\Framework\Exception\NoSuchEntityException
7678
*/
7779
private function getQuoteMaskId(int $quoteId): string
7880
{
79-
$maskedId = $this->quoteIdToMaskedQuoteId->execute($quoteId);
80-
if ($maskedId === '') {
81-
$quoteIdMask = $this->quoteIdMaskFactory->create();
82-
$quoteIdMask->setQuoteId($quoteId);
83-
84-
$this->quoteIdMaskResourceModel->save($quoteIdMask);
85-
$maskedId = $quoteIdMask->getMaskedId();
81+
try {
82+
$maskedId = $this->quoteIdToMaskedQuoteId->execute($quoteId);
83+
} catch (NoSuchEntityException $exception) {
84+
throw new GraphQlNoSuchEntityException(__('Cart id is not '));
8685
}
87-
8886
return $maskedId;
8987
}
9088
}

app/code/Magento/QuoteGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ type PlaceOrderOutput {
192192
}
193193

194194
type Cart {
195-
cart_id: ID! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartId") @doc(description: "Cart Id of the cart")
195+
cart_id: ID! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\MaskedCartId") @doc(description: "The ID of the cart. The value can be an Int or String.")
196196
items: [CartItemInterface] @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartItems")
197197
applied_coupon: AppliedCoupon @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\AppliedCoupon") @doc(description:"An array of coupons that have been applied to the cart") @deprecated(reason: "Use applied_coupons instead ")
198198
applied_coupons: [AppliedCoupon] @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\AppliedCoupons") @doc(description:"An array of `AppliedCoupon` objects. Each object contains the `code` text attribute, which specifies the coupon code")

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
use Magento\Integration\Api\CustomerTokenServiceInterface;
1313
use Magento\TestFramework\Helper\Bootstrap;
1414
use Magento\TestFramework\TestCase\GraphQlAbstract;
15-
use Magento\Quote\Api\CartManagementInterface;
16-
use Magento\Quote\Api\CartRepositoryInterface;
17-
use Magento\Quote\Model\QuoteIdMaskFactory;
1815

1916
/**
2017
* Test for getting Customer cart information
@@ -90,7 +87,7 @@ public function testGetNewCustomerCart()
9087
* Query for customer cart with no customer token passed
9188
*
9289
* @expectedException Exception
93-
* @expectedExceptionMessage User cannot access the cart unless loggedIn and with a valid customer token
90+
* @expectedExceptionMessage The request is allowed for logged in customer
9491
*/
9592
public function testGetCustomerCartWithNoCustomerToken()
9693
{
@@ -115,7 +112,7 @@ public function testGetCustomerCartAfterTokenRevoked()
115112
$this->revokeCustomerToken();
116113
$customerCartQuery = $this->getCustomerCartQuery();
117114
$this->expectExceptionMessage(
118-
"User cannot access the cart unless loggedIn and with a valid customer token"
115+
'The request is allowed for logged in customer'
119116
);
120117
$this->graphQlQuery($customerCartQuery, [], '', $this->headers);
121118
}

0 commit comments

Comments
 (0)