public function CartSession::addToCart in Basic cart 8
Same name and namespace in other branches
- 8.6 src/CartSession.php \Drupal\basic_cart\CartSession::addToCart()
- 8.0 src/CartSession.php \Drupal\basic_cart\CartSession::addToCart()
- 8.2 src/CartSession.php \Drupal\basic_cart\CartSession::addToCart()
- 8.3 src/CartSession.php \Drupal\basic_cart\CartSession::addToCart()
- 8.4 src/CartSession.php \Drupal\basic_cart\CartSession::addToCart()
- 8.5 src/CartSession.php \Drupal\basic_cart\CartSession::addToCart()
Overrides CartInterface::addToCart
File
- src/
CartSession.php, line 70
Class
- CartSession
- Class CartSession.
Namespace
Drupal\basic_cartCode
public function addToCart($id, $params = array()) {
$config = Settings::cartSettings();
if (!empty($params)) {
$quantity = $params['quantity'];
$entitytype = $params['entitytype'];
$quantity = $params['quantity'];
if ($id > 0 && $quantity > 0) {
// If a node is added more times, just update the quantity.
$cart = self::getCart();
if ($config
->get('quantity_status') && !empty($cart['cart']) && in_array($id, array_keys($cart['cart']))) {
// Clicked 2 times on add to cart button. Increment quantity.
$_SESSION['basic_cart']['cart_quantity'][$id] += $quantity;
}
else {
$entity = \Drupal::entityTypeManager()
->getStorage($entitytype)
->load($id);
$_SESSION['basic_cart']['cart'][$id] = $entity;
$_SESSION['basic_cart']['cart_quantity'][$id] = $quantity;
}
}
Settings::cartUpdatedMessage();
}
}