23
23
/**
24
24
* Get customer cart or create empty cart. Ensure mask_id is created
25
25
*/
26
- readonly class CustomerEmptyCartResolver
26
+ class CustomerEmptyCartResolver
27
27
{
28
28
/**
29
29
* @param CartManagementInterface $cartManagement
33
33
* @param QuoteIdMaskResourceModel $quoteIdMaskResourceModel
34
34
*/
35
35
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
+ ) {
42
42
}
43
43
44
44
/**
@@ -47,6 +47,7 @@ public function __construct(
47
47
* @param CustomerCartResolver $subject
48
48
* @param Closure $proceed
49
49
* @param int $customerId
50
+ * @param $predefinedMaskedQuoteId
50
51
* @return Quote
51
52
* @throws NoSuchEntityException
52
53
* @throws LocalizedException
@@ -55,7 +56,8 @@ public function __construct(
55
56
public function aroundResolve (
56
57
CustomerCartResolver $ subject ,
57
58
Closure $ proceed ,
58
- int $ customerId
59
+ int $ customerId ,
60
+ $ predefinedMaskedQuoteId = null
59
61
): Quote {
60
62
try {
61
63
/** @var Quote $cart */
@@ -65,7 +67,7 @@ public function aroundResolve(
65
67
$ cart = $ this ->cartManagement ->getCartForCustomer ($ customerId );
66
68
}
67
69
try {
68
- $ this ->ensureQuoteMaskIdExist ((int )$ cart ->getId ());
70
+ $ this ->ensureQuoteMaskIdExist ((int )$ cart ->getId (), $ predefinedMaskedQuoteId );
69
71
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
70
72
} catch (AlreadyExistsException $ e ) {
71
73
// do nothing, we already have masked id
@@ -78,10 +80,11 @@ public function aroundResolve(
78
80
* Create masked id for customer's active quote if it's not exists
79
81
*
80
82
* @param int $quoteId
83
+ * @param $predefinedMaskedQuoteId
81
84
* @return void
82
85
* @throws AlreadyExistsException
83
86
*/
84
- private function ensureQuoteMaskIdExist (int $ quoteId ): void
87
+ private function ensureQuoteMaskIdExist (int $ quoteId, $ predefinedMaskedQuoteId ): void
85
88
{
86
89
try {
87
90
$ maskedId = $ this ->quoteIdToMaskedQuoteId ->execute ($ quoteId );
@@ -91,6 +94,9 @@ private function ensureQuoteMaskIdExist(int $quoteId): void
91
94
if ($ maskedId === '' ) {
92
95
$ quoteIdMask = $ this ->quoteIdMaskFactory ->create ();
93
96
$ quoteIdMask ->setQuoteId ($ quoteId );
97
+ if (null !== $ predefinedMaskedQuoteId ) {
98
+ $ quoteIdMask ->setMaskedId ($ predefinedMaskedQuoteId );
99
+ }
94
100
$ this ->quoteIdMaskResourceModel ->save ($ quoteIdMask );
95
101
}
96
102
}
0 commit comments