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 function updateProductAction() { if (isset($_GET["id"])) { $product = ProductManager::getProduct($_GET["id"]); } require "src/Ecommerce/view/back/updateproduct.php"; if (isset($_POST["update"])) { if (!empty($_POST["name"]) && !empty($_POST["description"]) && !empty($_POST["price"])) { ProductManager::updateProduct($_POST["id"], $_POST["name"], $_POST["description"], $_POST["price"]); header("Location: index.php?controller=Back&method=management"); } else { echo "champs incomplets"; } } }
public function addToCartAction() { if (isset($_GET['id']) && ProductManager::getProduct($_GET['id'])) { CartProductManager::addProduct($_GET['id']); } else { header('Location: index.php'); } header('Location: index.php?controller=Front&method=cart'); }