You are here

public function CartTable::getCart in Basic cart 8

Same name and namespace in other branches
  1. 8.6 src/CartTable.php \Drupal\basic_cart\CartTable::getCart()
  2. 8.0 src/CartTable.php \Drupal\basic_cart\CartTable::getCart()
  3. 8.2 src/CartTable.php \Drupal\basic_cart\CartTable::getCart()
  4. 8.3 src/CartTable.php \Drupal\basic_cart\CartTable::getCart()
  5. 8.4 src/CartTable.php \Drupal\basic_cart\CartTable::getCart()
  6. 8.5 src/CartTable.php \Drupal\basic_cart\CartTable::getCart()

* Function for shopping cart retrieval. * *

Parameters

int $nid: * We are using the node id to store the node in the shopping cart * * @return mixed * Returning the shopping cart contents. * An empty array if there is nothing in the cart

Overrides CartInterface::getCart

1 call to CartTable::getCart()
CartTable::addToCart in src/CartTable.php

File

src/CartTable.php, line 36

Class

CartTable
Class CartTable.

Namespace

Drupal\basic_cart

Code

public function getCart($nid = NULL) {
  if (isset($nid)) {
    return array(
      "cart" => $_SESSION['basic_cart']['cart'][$nid],
      "cart_quantity" => $_SESSION['basic_cart']['cart_quantity'][$nid],
    );
  }
  if (isset($_SESSION['basic_cart']['cart'])) {
    return array(
      "cart" => $_SESSION['basic_cart']['cart'],
      "cart_quantity" => $_SESSION['basic_cart']['cart_quantity'],
    );
  }

  // Empty cart.
  return array(
    "cart" => array(),
    "cart_quantity" => array(),
  );
}