Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ParamOverriderCartId.php
Go to the documentation of this file.
1 <?php
8 
13 
18 {
22  private $userContext;
23 
27  private $cartManagement;
28 
35  public function __construct(
36  UserContextInterface $userContext,
37  CartManagementInterface $cartManagement
38  ) {
39  $this->userContext = $userContext;
40  $this->cartManagement = $cartManagement;
41  }
42 
46  public function getOverriddenValue()
47  {
48  try {
49  if ($this->userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) {
50  $customerId = $this->userContext->getUserId();
51 
53  $cart = $this->cartManagement->getCartForCustomer($customerId);
54  if ($cart) {
55  return $cart->getId();
56  }
57  }
58  } catch (NoSuchEntityException $e) {
59  throw new NoSuchEntityException(__('Current customer does not have an active cart.'));
60  }
61  return null;
62  }
63 }
__()
Definition: __.php:13
$cartManagement
Definition: quote.php:16
__construct(UserContextInterface $userContext, CartManagementInterface $cartManagement)