You are here

public function CartSession::getCart in Basic cart 8

Same name and namespace in other branches
  1. 8.6 src/CartSession.php \Drupal\basic_cart\CartSession::getCart()
  2. 8.0 src/CartSession.php \Drupal\basic_cart\CartSession::getCart()
  3. 8.2 src/CartSession.php \Drupal\basic_cart\CartSession::getCart()
  4. 8.3 src/CartSession.php \Drupal\basic_cart\CartSession::getCart()
  5. 8.4 src/CartSession.php \Drupal\basic_cart\CartSession::getCart()
  6. 8.5 src/CartSession.php \Drupal\basic_cart\CartSession::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 CartSession::getCart()
CartSession::addToCart in src/CartSession.php

File

src/CartSession.php, line 33

Class

CartSession
Class CartSession.

Namespace

Drupal\basic_cart

Code

public function getCart($nid = NULL) {

  //print_r($nid); die;
  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(),
  );
}