You are here

public function CartProvider::getCartId in Commerce Core 8.2

Gets the cart order ID for the given store and user.

Parameters

string $order_type: The order type ID.

\Drupal\commerce_store\Entity\StoreInterface|null $store: The store. If omitted, the current store is assumed.

\Drupal\Core\Session\AccountInterface|null $account: The user. If empty, the current user is assumed.

Return value

int|null The cart order ID, or NULL if none found.

Overrides CartProviderInterface::getCartId

2 calls to CartProvider::getCartId()
CartProvider::createCart in modules/cart/src/CartProvider.php
Creates a cart order for the given store and user.
CartProvider::getCart in modules/cart/src/CartProvider.php
Gets the cart order for the given store and user.

File

modules/cart/src/CartProvider.php, line 147

Class

CartProvider
Default implementation of the cart provider.

Namespace

Drupal\commerce_cart

Code

public function getCartId($order_type, StoreInterface $store = NULL, AccountInterface $account = NULL) {
  $cart_id = NULL;
  $cart_data = $this
    ->loadCartData($account);
  if ($cart_data) {
    $store = $store ?: $this->currentStore
      ->getStore();
    $search = [
      'type' => $order_type,
      'store_id' => $store
        ->id(),
    ];
    $cart_id = array_search($search, $cart_data);
  }
  return $cart_id;
}