Skip to content

Commit 141c920

Browse files
committed
Return hashed cart id for both cases: logged in customer and guest
1 parent a62af8e commit 141c920

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77

88
namespace Magento\QuoteGraphQl\Model\Resolver\Cart;
99

10+
use Magento\Authorization\Model\UserContextInterface;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
1012
use Magento\Framework\GraphQl\Query\Resolver\Value;
1113
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
12-
use Magento\Framework\GraphQl\Config\Element\Field;
1314
use Magento\Framework\GraphQl\Query\ResolverInterface;
1415
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15-
use Magento\Quote\Api\GuestCartManagementInterface;
1616
use Magento\Quote\Api\CartManagementInterface;
17-
use Magento\Authorization\Model\UserContextInterface;
17+
use Magento\Quote\Api\GuestCartManagementInterface;
18+
use Magento\Quote\Model\QuoteIdMask;
19+
use Magento\Quote\Model\QuoteIdMaskFactory;
1820

1921
/**
2022
* {@inheritdoc}
@@ -36,6 +38,11 @@ class CreateEmptyCart implements ResolverInterface
3638
*/
3739
private $valueFactory;
3840

41+
/**
42+
* @var QuoteIdMaskFactory
43+
*/
44+
private $quoteIdMaskFactory;
45+
3946
/**
4047
* @var UserContextInterface
4148
*/
@@ -46,17 +53,20 @@ class CreateEmptyCart implements ResolverInterface
4653
* @param GuestCartManagementInterface $guestCartManagement
4754
* @param ValueFactory $valueFactory
4855
* @param UserContextInterface $userContext
56+
* @param QuoteIdMaskFactory $quoteIdMaskFactory
4957
*/
5058
public function __construct(
5159
CartManagementInterface $cartManagement,
5260
GuestCartManagementInterface $guestCartManagement,
5361
ValueFactory $valueFactory,
54-
UserContextInterface $userContext
62+
UserContextInterface $userContext,
63+
QuoteIdMaskFactory $quoteIdMaskFactory
5564
) {
5665
$this->cartManagement = $cartManagement;
5766
$this->guestCartManagement = $guestCartManagement;
5867
$this->valueFactory = $valueFactory;
5968
$this->userContext = $userContext;
69+
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
6070
}
6171

6272
/**
@@ -68,6 +78,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6878

6979
if ($customerId) {
7080
$cartId = $this->cartManagement->createEmptyCartForCustomer($customerId);
81+
/** @var QuoteIdMask $quoteIdMask */
82+
$quoteIdMask = $this->quoteIdMaskFactory->create();
83+
$quoteIdMask->setQuoteId($cartId)->save();
84+
$cartId = $quoteIdMask->getMaskedId();
7185
} else {
7286
$cartId = $this->guestCartManagement->createEmptyCart();
7387
}

0 commit comments

Comments
 (0)