Skip to content

Commit 4bad8f9

Browse files
authored
ENGCOM-7681: #28564: Handle empty masked quote id return case #28714
2 parents e45103b + ce9a700 commit 4bad8f9

File tree

1 file changed

+15
-54
lines changed

1 file changed

+15
-54
lines changed

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

Lines changed: 15 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,32 @@
77

88
namespace Magento\QuoteGraphQl\Model\Resolver;
99

10-
use Magento\Framework\Exception\NoSuchEntityException;
1110
use Magento\Framework\GraphQl\Config\Element\Field;
1211
use Magento\Framework\GraphQl\Query\ResolverInterface;
1312
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14-
use Magento\QuoteGraphQl\Model\Cart\CreateEmptyCartForCustomer;
1513
use Magento\GraphQl\Model\Query\ContextInterface;
1614
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
17-
use Magento\Quote\Api\CartManagementInterface;
18-
use Magento\Quote\Model\QuoteIdMaskFactory;
19-
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
20-
use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResourceModel;
15+
use Magento\Quote\Model\Cart\CustomerCartResolver;
2116

2217
/**
2318
* Get cart for the customer
2419
*/
2520
class CustomerCart implements ResolverInterface
2621
{
2722
/**
28-
* @var CreateEmptyCartForCustomer
23+
* @var CustomerCartResolver
2924
*/
30-
private $createEmptyCartForCustomer;
25+
private $customerCartResolver;
3126

3227
/**
33-
* @var CartManagementInterface
34-
*/
35-
private $cartManagement;
36-
37-
/**
38-
* @var QuoteIdMaskFactory
39-
*/
40-
private $quoteIdMaskFactory;
41-
42-
/**
43-
* @var QuoteIdMaskResourceModel
44-
*/
45-
private $quoteIdMaskResourceModel;
46-
/**
47-
* @var QuoteIdToMaskedQuoteIdInterface
48-
*/
49-
private $quoteIdToMaskedQuoteId;
50-
51-
/**
52-
* @param CreateEmptyCartForCustomer $createEmptyCartForCustomer
53-
* @param CartManagementInterface $cartManagement
54-
* @param QuoteIdMaskFactory $quoteIdMaskFactory
55-
* @param QuoteIdMaskResourceModel $quoteIdMaskResourceModel
56-
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
28+
* CustomerCart constructor.
29+
*
30+
* @param CustomerCartResolver $customerCartResolver
5731
*/
5832
public function __construct(
59-
CreateEmptyCartForCustomer $createEmptyCartForCustomer,
60-
CartManagementInterface $cartManagement,
61-
QuoteIdMaskFactory $quoteIdMaskFactory,
62-
QuoteIdMaskResourceModel $quoteIdMaskResourceModel,
63-
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
33+
CustomerCartResolver $customerCartResolver
6434
) {
65-
$this->createEmptyCartForCustomer = $createEmptyCartForCustomer;
66-
$this->cartManagement = $cartManagement;
67-
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
68-
$this->quoteIdMaskResourceModel = $quoteIdMaskResourceModel;
69-
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
35+
$this->customerCartResolver = $customerCartResolver;
7036
}
7137

7238
/**
@@ -76,22 +42,17 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7642
{
7743
$currentUserId = $context->getUserId();
7844

79-
/** @var ContextInterface $context */
45+
/**
46+
* @var ContextInterface $context
47+
*/
8048
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
8149
throw new GraphQlAuthorizationException(__('The request is allowed for logged in customer'));
8250
}
83-
try {
84-
$cart = $this->cartManagement->getCartForCustomer($currentUserId);
85-
} catch (NoSuchEntityException $e) {
86-
$this->createEmptyCartForCustomer->execute($currentUserId, null);
87-
$cart = $this->cartManagement->getCartForCustomer($currentUserId);
88-
}
8951

90-
$maskedId = $this->quoteIdToMaskedQuoteId->execute((int) $cart->getId());
91-
if (empty($maskedId)) {
92-
$quoteIdMask = $this->quoteIdMaskFactory->create();
93-
$quoteIdMask->setQuoteId((int) $cart->getId());
94-
$this->quoteIdMaskResourceModel->save($quoteIdMask);
52+
try {
53+
$cart = $this->customerCartResolver->resolve($currentUserId);
54+
} catch (\Exception $e) {
55+
$cart = null;
9556
}
9657

9758
return [

0 commit comments

Comments
 (0)