cart.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. require_once __DIR__ . '/config.php';
  3. require_once __DIR__ . '/includes/functions.php';
  4. $pageTitle = 'Warenkorb';
  5. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['remove_item_index'])) {
  6. removeCartItemByIndex((int) $_POST['remove_item_index']);
  7. }
  8. $cartItems = getCartItemsDetailed();
  9. $cartNotice = consumeFlashMessage('cart_notice');
  10. include __DIR__ . '/includes/header.php';
  11. ?>
  12. <h2>Warenkorb</h2>
  13. <?php if ($cartNotice !== null): ?>
  14. <div class="alert alert-<?php echo escape($cartNotice['type']); ?>">
  15. <?php echo escape($cartNotice['message']); ?>
  16. </div>
  17. <?php endif; ?>
  18. <?php if (empty($cartItems)): ?>
  19. <div class="alert alert-info">
  20. <p>Ihr Warenkorb ist leer.</p>
  21. <a href="index.php" class="btn">Weiter zur Produktübersicht</a>
  22. </div>
  23. <?php else: ?>
  24. <?php foreach ($cartItems as $cartItem): ?>
  25. <div class="cart-item">
  26. <div class="cart-item-info">
  27. <h3><?php echo escape($cartItem['product']['name']); ?></h3>
  28. <?php if ($cartItem['size'] !== ''): ?>
  29. <p><strong>Größe:</strong> <?php echo escape($cartItem['size']); ?></p>
  30. <?php endif; ?>
  31. <?php if ($cartItem['availability_label'] !== ''): ?>
  32. <p><strong>Lieferhinweis:</strong> <?php echo escape($cartItem['availability_label']); ?></p>
  33. <?php endif; ?>
  34. </div>
  35. <div class="cart-item-actions">
  36. <form method="POST">
  37. <button type="submit" name="remove_item_index" value="<?php echo (int) $cartItem['cart_index']; ?>" class="btn btn-secondary btn-small">Entfernen</button>
  38. </form>
  39. </div>
  40. </div>
  41. <?php endforeach; ?>
  42. <div class="cart-actions">
  43. <div class="cart-buttons">
  44. <a href="index.php" class="btn btn-secondary">Weiter auswählen</a>
  45. <a href="checkout.php" class="btn">Zur Bestellung</a>
  46. </div>
  47. </div>
  48. <?php endif; ?>
  49. <?php include __DIR__ . '/includes/footer.php'; ?>