$quantity) { $quantity = (int)$quantity; if ($quantity <= 0) { // Remove from cart $_SESSION['cart'] = array_filter($_SESSION['cart'], function($item) use ($productId) { return $item['product_id'] != $productId; }); $_SESSION['cart'] = array_values($_SESSION['cart']); // Re-index } else { // Update quantity foreach ($_SESSION['cart'] as &$item) { if ($item['product_id'] == $productId) { $item['quantity'] = $quantity; break; } } } } } elseif (isset($_POST['remove_item'])) { $productId = (int)$_POST['product_id']; $size = isset($_POST['size']) ? sanitize($_POST['size']) : null; $_SESSION['cart'] = array_filter($_SESSION['cart'], function($item) use ($productId, $size) { if ($item['product_id'] != $productId) { return true; } // If size is specified, only remove items with matching size if ($size !== null) { return !(isset($item['size']) && $item['size'] === $size); } // If no size specified, remove all items of this product return false; }); $_SESSION['cart'] = array_values($_SESSION['cart']); // Re-index } } $cart = $_SESSION['cart'] ?? []; $cartItems = []; $total = 0; foreach ($cart as $index => $item) { $product = getProductById($item['product_id']); if ($product) { $itemTotal = $product['price'] * $item['quantity']; $total += $itemTotal; $cartItems[] = [ 'product' => $product, 'quantity' => $item['quantity'], 'total' => $itemTotal, 'size' => isset($item['size']) ? $item['size'] : null, 'cart_index' => $index ]; } } include __DIR__ . '/includes/header.php'; ?>

Warenkorb

Ihr Warenkorb ist leer.

Weiter einkaufen

Größe:

Einzelpreis:

Gesamt:

= $cartItem['quantity']; ?>

Lagerbestand: Stück
Nicht genügend Lagerbestand!

Gesamtsumme:
Zur Reservierung