Skip to content

Commit ddf3bbd

Browse files
committed
ACP2E-3255: [GRAPHQL] model value should be specified when getting customerCart
- Fixed the static test failure.
1 parent c18dd5a commit ddf3bbd

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* Class to create an empty cart and quote for a specified customer.
2020
*/
21-
readonly class CreateEmptyCartForCustomer
21+
class CreateEmptyCartForCustomer
2222
{
2323
/**
2424
* @param StoreManagerInterface $storeManager
@@ -27,10 +27,10 @@
2727
* @param QuoteFactory $quoteFactory
2828
*/
2929
public function __construct(
30-
private StoreManagerInterface $storeManager,
31-
private CartRepositoryInterface $quoteRepository,
32-
private CustomerRepositoryInterface $customerRepository,
33-
private QuoteFactory $quoteFactory,
30+
private readonly StoreManagerInterface $storeManager,
31+
private readonly CartRepositoryInterface $quoteRepository,
32+
private readonly CustomerRepositoryInterface $customerRepository,
33+
private readonly QuoteFactory $quoteFactory,
3434
) {
3535
}
3636

app/code/Magento/QuoteGraphQl/Plugin/Model/Cart/CustomerEmptyCartResolver.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* Get customer cart or create empty cart. Ensure mask_id is created
2525
*/
26-
readonly class CustomerEmptyCartResolver
26+
class CustomerEmptyCartResolver
2727
{
2828
/**
2929
* @param CartManagementInterface $cartManagement
@@ -33,12 +33,12 @@
3333
* @param QuoteIdMaskResourceModel $quoteIdMaskResourceModel
3434
*/
3535
public function __construct(
36-
private CartManagementInterface $cartManagement,
37-
private CreateEmptyCartForCustomer $createEmptyCartForCustomer,
38-
private QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId,
39-
private QuoteIdMaskFactory $quoteIdMaskFactory,
40-
private QuoteIdMaskResourceModel $quoteIdMaskResourceModel
41-
){
36+
private readonly CartManagementInterface $cartManagement,
37+
private readonly CreateEmptyCartForCustomer $createEmptyCartForCustomer,
38+
private readonly QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId,
39+
private readonly QuoteIdMaskFactory $quoteIdMaskFactory,
40+
private readonly QuoteIdMaskResourceModel $quoteIdMaskResourceModel
41+
) {
4242
}
4343

4444
/**
@@ -47,6 +47,7 @@ public function __construct(
4747
* @param CustomerCartResolver $subject
4848
* @param Closure $proceed
4949
* @param int $customerId
50+
* @param $predefinedMaskedQuoteId
5051
* @return Quote
5152
* @throws NoSuchEntityException
5253
* @throws LocalizedException
@@ -55,7 +56,8 @@ public function __construct(
5556
public function aroundResolve(
5657
CustomerCartResolver $subject,
5758
Closure $proceed,
58-
int $customerId
59+
int $customerId,
60+
$predefinedMaskedQuoteId = null
5961
): Quote {
6062
try {
6163
/** @var Quote $cart */
@@ -65,7 +67,7 @@ public function aroundResolve(
6567
$cart = $this->cartManagement->getCartForCustomer($customerId);
6668
}
6769
try {
68-
$this->ensureQuoteMaskIdExist((int)$cart->getId());
70+
$this->ensureQuoteMaskIdExist((int)$cart->getId(), $predefinedMaskedQuoteId);
6971
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
7072
} catch (AlreadyExistsException $e) {
7173
// do nothing, we already have masked id
@@ -78,10 +80,11 @@ public function aroundResolve(
7880
* Create masked id for customer's active quote if it's not exists
7981
*
8082
* @param int $quoteId
83+
* @param $predefinedMaskedQuoteId
8184
* @return void
8285
* @throws AlreadyExistsException
8386
*/
84-
private function ensureQuoteMaskIdExist(int $quoteId): void
87+
private function ensureQuoteMaskIdExist(int $quoteId, $predefinedMaskedQuoteId): void
8588
{
8689
try {
8790
$maskedId = $this->quoteIdToMaskedQuoteId->execute($quoteId);
@@ -91,6 +94,9 @@ private function ensureQuoteMaskIdExist(int $quoteId): void
9194
if ($maskedId === '') {
9295
$quoteIdMask = $this->quoteIdMaskFactory->create();
9396
$quoteIdMask->setQuoteId($quoteId);
97+
if (null !== $predefinedMaskedQuoteId) {
98+
$quoteIdMask->setMaskedId($predefinedMaskedQuoteId);
99+
}
94100
$this->quoteIdMaskResourceModel->save($quoteIdMask);
95101
}
96102
}

0 commit comments

Comments
 (0)