You are here

interface CartSessionInterface in Commerce Core 8.2

Stores cart ids in the anonymous user's session.

Allows the system to keep track of which cart orders belong to the anonymous user. The session is the only available storage in this case, since all anonymous users share the same user id (0).

Tracks active and completed carts separately.

Hierarchy

Expanded class hierarchy of CartSessionInterface

All classes that implement CartSessionInterface

See also

\Drupal\commerce_cart\CartProviderInterface

3 files declare their use of CartSessionInterface
CheckoutController.php in modules/checkout/src/Controller/CheckoutController.php
commerce_cart.module in modules/cart/commerce_cart.module
Implements the shopping cart system and add to cart features.
QueryAccessSubscriber.php in modules/cart/src/EventSubscriber/QueryAccessSubscriber.php

File

modules/cart/src/CartSessionInterface.php, line 16

Namespace

Drupal\commerce_cart
View source
interface CartSessionInterface {

  // The cart session types.
  const ACTIVE = 'active';
  const COMPLETED = 'completed';

  /**
   * Gets all cart order ids from the session.
   *
   * @param string $type
   *   The cart session type.
   *
   * @return int[]
   *   A list of cart orders ids.
   */
  public function getCartIds($type = self::ACTIVE);

  /**
   * Adds the given cart order ID to the session.
   *
   * @param int $cart_id
   *   The cart order ID.
   * @param string $type
   *   The cart session type.
   */
  public function addCartId($cart_id, $type = self::ACTIVE);

  /**
   * Checks whether the given cart order ID exists in the session.
   *
   * @param int $cart_id
   *   The cart order ID.
   * @param string $type
   *   The cart session type.
   *
   * @return bool
   *   TRUE if the given cart order ID exists in the session, FALSE otherwise.
   */
  public function hasCartId($cart_id, $type = self::ACTIVE);

  /**
   * Deletes the given cart order id from the session.
   *
   * @param int $cart_id
   *   The cart order ID.
   * @param string $type
   *   The cart session type.
   */
  public function deleteCartId($cart_id, $type = self::ACTIVE);

}

Members

Namesort descending Modifiers Type Description Overrides
CartSessionInterface::ACTIVE constant
CartSessionInterface::addCartId public function Adds the given cart order ID to the session. 1
CartSessionInterface::COMPLETED constant
CartSessionInterface::deleteCartId public function Deletes the given cart order id from the session. 1
CartSessionInterface::getCartIds public function Gets all cart order ids from the session. 1
CartSessionInterface::hasCartId public function Checks whether the given cart order ID exists in the session. 1