0) { // If cart is not empty and new item is from a different restaurant, clear the cart if (!empty($_SESSION['cart']) && $_SESSION['cart_restaurant'] != $restaurant_id) { $_SESSION['cart'] = []; } $_SESSION['cart_restaurant'] = $restaurant_id; // Add or update item in cart if (isset($_SESSION['cart'][$menu_item_id])) { $_SESSION['cart'][$menu_item_id] += $quantity; } else { $_SESSION['cart'][$menu_item_id] = $quantity; } } header('Location: menu.php?id=' . $restaurant_id); exit; case 'update': if ($menu_item_id && $quantity > 0) { $_SESSION['cart'][$menu_item_id] = $quantity; } header('Location: cart.php'); exit; case 'remove': if ($menu_item_id) { unset($_SESSION['cart'][$menu_item_id]); } header('Location: cart.php'); exit; case 'clear': $_SESSION['cart'] = []; $_SESSION['cart_restaurant'] = null; header('Location: cart.php'); exit; }