public static function addProduct($id) { if (!isset($_SESSION["cart"])) { $_SESSION["cart"] = []; } $product = ProductManager::getProduct($id); $cartProduct = new CartProduct($product, 1); if (array_key_exists($cartProduct->getId(), $_SESSION["cart"])) { $quantity = $_SESSION["cart"][$cartProduct->getId()]->getQuantity(); $_SESSION["cart"][$cartProduct->getId()]->setQuantity($quantity + 1); } else { $_SESSION["cart"][$cartProduct->getId()] = $cartProduct; } }
public static function update(CartProduct $oCartProduct) { if (!array_key_exists('cart', $_SESSION)) { $_SESSION['cart'] = array(); } $_SESSION['cart'][$oCartProduct->getId()] = $oCartProduct->getQuantity(); }