16
16
use Magento \Quote \Api \CartManagementInterface ;
17
17
use Magento \Quote \Api \GuestCartManagementInterface ;
18
18
use Magento \Quote \Model \QuoteIdToMaskedQuoteIdInterface ;
19
+ use Magento \Quote \Model \QuoteIdMaskFactory ;
19
20
20
21
/**
21
22
* @inheritdoc
@@ -26,7 +27,6 @@ class CreateEmptyCart implements ResolverInterface
26
27
* @var CartManagementInterface
27
28
*/
28
29
private $ cartManagement ;
29
-
30
30
/**
31
31
* @var GuestCartManagementInterface
32
32
*/
@@ -47,25 +47,33 @@ class CreateEmptyCart implements ResolverInterface
47
47
*/
48
48
private $ userContext ;
49
49
50
+ /**
51
+ * @var QuoteIdMaskFactory
52
+ */
53
+ private $ quoteIdMaskFactory ;
54
+
50
55
/**
51
56
* @param CartManagementInterface $cartManagement
52
57
* @param GuestCartManagementInterface $guestCartManagement
53
58
* @param ValueFactory $valueFactory
54
59
* @param UserContextInterface $userContext
55
60
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId
61
+ * @param QuoteIdMaskFactory $quoteIdMaskFactory
56
62
*/
57
63
public function __construct (
58
64
CartManagementInterface $ cartManagement ,
59
65
GuestCartManagementInterface $ guestCartManagement ,
60
66
ValueFactory $ valueFactory ,
61
67
UserContextInterface $ userContext ,
62
- QuoteIdToMaskedQuoteIdInterface $ quoteIdToMaskedId
68
+ QuoteIdToMaskedQuoteIdInterface $ quoteIdToMaskedId ,
69
+ QuoteIdMaskFactory $ quoteIdMaskFactory
63
70
) {
64
71
$ this ->cartManagement = $ cartManagement ;
65
72
$ this ->guestCartManagement = $ guestCartManagement ;
66
73
$ this ->valueFactory = $ valueFactory ;
67
74
$ this ->userContext = $ userContext ;
68
75
$ this ->quoteIdToMaskedId = $ quoteIdToMaskedId ;
76
+ $ this ->quoteIdMaskFactory = $ quoteIdMaskFactory ;
69
77
}
70
78
71
79
/**
@@ -77,7 +85,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
77
85
78
86
if (null !== $ customerId ) {
79
87
$ 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
+ }
81
95
} else {
82
96
$ maskedQuoteId = $ this ->guestCartManagement ->createEmptyCart ();
83
97
}
0 commit comments