public function CartSession::getCart in Basic cart 8.5
Same name and namespace in other branches
- 8.6 src/CartSession.php \Drupal\basic_cart\CartSession::getCart()
- 8 src/CartSession.php \Drupal\basic_cart\CartSession::getCart()
- 8.0 src/CartSession.php \Drupal\basic_cart\CartSession::getCart()
- 8.2 src/CartSession.php \Drupal\basic_cart\CartSession::getCart()
- 8.3 src/CartSession.php \Drupal\basic_cart\CartSession::getCart()
- 8.4 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 value
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 - Add to cart.
File
- src/
CartSession.php, line 34
Class
- CartSession
- Class CartSession.
Namespace
Drupal\basic_cartCode
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(),
);
}