cart.php 2.3 KB

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