Skip to content

Commit 8771f41

Browse files
committed
Quote masked id creation logic moved to create cart resolver
1 parent 439df24 commit 8771f41

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

app/code/Magento/Quote/Model/QuoteIdToMaskedQuoteId.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,37 @@
88
namespace Magento\Quote\Model;
99

1010
use Magento\Quote\Api\CartRepositoryInterface;
11+
use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResource;
1112

1213
class QuoteIdToMaskedQuoteId implements QuoteIdToMaskedQuoteIdInterface
1314
{
1415
/**
1516
* @var QuoteIdMaskFactory
1617
*/
1718
private $quoteIdMaskFactory;
18-
1919
/**
2020
* @var CartRepositoryInterface
2121
*/
2222
private $cartRepository;
2323

24+
/**
25+
* @var QuoteIdMaskResource
26+
*/
27+
private $quoteIdMaskResource;
28+
2429
/**
2530
* @param QuoteIdMaskFactory $quoteIdMaskFactory
2631
* @param CartRepositoryInterface $cartRepository
32+
* @param QuoteIdMaskResource $quoteIdMaskResource
2733
*/
2834
public function __construct(
2935
QuoteIdMaskFactory $quoteIdMaskFactory,
30-
CartRepositoryInterface $cartRepository
36+
CartRepositoryInterface $cartRepository,
37+
QuoteIdMaskResource $quoteIdMaskResource
3138
) {
3239
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
3340
$this->cartRepository = $cartRepository;
41+
$this->quoteIdMaskResource = $quoteIdMaskResource;
3442
}
3543

3644
/**
@@ -42,8 +50,9 @@ public function execute(int $quoteId): string
4250
$this->cartRepository->get($quoteId);
4351

4452
$quoteIdMask = $this->quoteIdMaskFactory->create();
45-
$quoteIdMask->setQuoteId($quoteId)->save();
53+
$this->quoteIdMaskResource->load($quoteIdMask, $quoteId, 'quote_id');
54+
$maskedId = $quoteIdMask->getMaskedId() ?? '';
4655

47-
return $quoteIdMask->getMaskedId();
56+
return $maskedId;
4857
}
4958
}

app/code/Magento/QuoteGraphQl/Model/Resolver/Cart/CreateEmptyCart.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Quote\Api\CartManagementInterface;
1717
use Magento\Quote\Api\GuestCartManagementInterface;
1818
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
19+
use Magento\Quote\Model\QuoteIdMaskFactory;
1920

2021
/**
2122
* @inheritdoc
@@ -26,7 +27,6 @@ class CreateEmptyCart implements ResolverInterface
2627
* @var CartManagementInterface
2728
*/
2829
private $cartManagement;
29-
3030
/**
3131
* @var GuestCartManagementInterface
3232
*/
@@ -47,25 +47,33 @@ class CreateEmptyCart implements ResolverInterface
4747
*/
4848
private $userContext;
4949

50+
/**
51+
* @var QuoteIdMaskFactory
52+
*/
53+
private $quoteIdMaskFactory;
54+
5055
/**
5156
* @param CartManagementInterface $cartManagement
5257
* @param GuestCartManagementInterface $guestCartManagement
5358
* @param ValueFactory $valueFactory
5459
* @param UserContextInterface $userContext
5560
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId
61+
* @param QuoteIdMaskFactory $quoteIdMaskFactory
5662
*/
5763
public function __construct(
5864
CartManagementInterface $cartManagement,
5965
GuestCartManagementInterface $guestCartManagement,
6066
ValueFactory $valueFactory,
6167
UserContextInterface $userContext,
62-
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId
68+
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId,
69+
QuoteIdMaskFactory $quoteIdMaskFactory
6370
) {
6471
$this->cartManagement = $cartManagement;
6572
$this->guestCartManagement = $guestCartManagement;
6673
$this->valueFactory = $valueFactory;
6774
$this->userContext = $userContext;
6875
$this->quoteIdToMaskedId = $quoteIdToMaskedId;
76+
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
6977
}
7078

7179
/**
@@ -77,7 +85,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7785

7886
if (null !== $customerId) {
7987
$quoteId = $this->cartManagement->createEmptyCartForCustomer($customerId);
80-
$maskedQuoteId = $this->quoteIdToMaskedId->execute($quoteId);
88+
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quoteId);
89+
90+
if (empty($maskedQuoteId)) {
91+
$quoteIdMask = $this->quoteIdMaskFactory->create();
92+
$quoteIdMask->setQuoteId($quoteId)->save();
93+
$maskedQuoteId = $quoteIdMask->getMaskedId();
94+
}
8195
} else {
8296
$maskedQuoteId = $this->guestCartManagement->createEmptyCart();
8397
}

0 commit comments

Comments
 (0)