Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CreateEmptyCart.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
17 
22 {
26  private $cartManagement;
27 
31  private $guestCartManagement;
32 
36  private $quoteIdToMaskedId;
37 
41  private $userContext;
42 
49  public function __construct(
50  CartManagementInterface $cartManagement,
51  GuestCartManagementInterface $guestCartManagement,
52  UserContextInterface $userContext,
53  QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId
54  ) {
55  $this->cartManagement = $cartManagement;
56  $this->guestCartManagement = $guestCartManagement;
57  $this->userContext = $userContext;
58  $this->quoteIdToMaskedId = $quoteIdToMaskedId;
59  }
60 
64  public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
65  {
66  $customerId = $this->userContext->getUserId();
67 
68  if (0 !== $customerId && null !== $customerId) {
69  $quoteId = $this->cartManagement->createEmptyCartForCustomer($customerId);
70  $maskedQuoteId = $this->quoteIdToMaskedId->execute($quoteId);
71  } else {
72  $maskedQuoteId = $this->guestCartManagement->createEmptyCart();
73  }
74 
75  return $maskedQuoteId;
76  }
77 }
$value
Definition: gender.phtml:16
__construct(CartManagementInterface $cartManagement, GuestCartManagementInterface $guestCartManagement, UserContextInterface $userContext, QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedId)
$cartManagement
Definition: quote.php:16
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52
resolve(Field $field, $context, ResolveInfo $info, array $value=null, array $args=null)