You are here

public function CartSession::deleteCartId in Commerce Core 8.2

Deletes the given cart order id from the session.

Parameters

int $cart_id: The cart order ID.

string $type: The cart session type.

Overrides CartSessionInterface::deleteCartId

File

modules/cart/src/CartSession.php, line 59

Class

CartSession
Default implementation of the cart session.

Namespace

Drupal\commerce_cart

Code

public function deleteCartId($cart_id, $type = self::ACTIVE) {
  $key = $this
    ->getSessionKey($type);
  $ids = $this->session
    ->get($key, []);
  $ids = array_diff($ids, [
    $cart_id,
  ]);
  if (!empty($ids)) {
    $this->session
      ->set($key, $ids);
  }
  else {

    // Remove the empty list to allow the system to clean up empty sessions.
    $this->session
      ->remove($key);
  }
}