cart.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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_product_id'])
  8. ) {
  9. if (validateCsrfToken($_POST['csrf_token'] ?? "")) {
  10. removeCartItem(
  11. (int) ($_POST['remove_product_id'] ?? 0),
  12. (string) ($_POST['remove_size'] ?? ""),
  13. );
  14. } else {
  15. setFlashMessage(
  16. "cart_notice",
  17. "error",
  18. "Ungültiges Token. Bitte versuchen Sie es erneut.",
  19. );
  20. header("Location: cart.php");
  21. exit();
  22. }
  23. }
  24. $cartItems = getCartItemsDetailed();
  25. $cartNotice = consumeFlashMessage("cart_notice");
  26. include __DIR__ . "/includes/header.php";
  27. ?>
  28. <h2>Warenkorb</h2>
  29. <?php if ($cartNotice !== null): ?>
  30. <div class="alert alert-<?php echo escape($cartNotice["type"]); ?>">
  31. <?php echo escape($cartNotice["message"]); ?>
  32. </div>
  33. <?php endif; ?>
  34. <?php if (empty($cartItems)): ?>
  35. <div class="alert alert-info">
  36. <p>Ihr Warenkorb ist leer.</p>
  37. <a href="index.php" class="btn">Weiter zur Produktübersicht</a>
  38. </div>
  39. <?php else: ?>
  40. <?php foreach ($cartItems as $cartItem): ?>
  41. <div class="cart-item">
  42. <div class="cart-item-info">
  43. <h3><?php echo escape($cartItem["product"]["name"]); ?></h3>
  44. <?php if ($cartItem["size"] !== ""): ?>
  45. <p><strong>Größe:</strong> <?php echo escape(
  46. $cartItem["size"],
  47. ); ?></p>
  48. <?php endif; ?>
  49. <?php if ($cartItem["availability_label"] !== ""): ?>
  50. <p><strong>Lieferhinweis:</strong> <?php echo escape(
  51. $cartItem["availability_label"],
  52. ); ?></p>
  53. <?php endif; ?>
  54. </div>
  55. <div class="cart-item-actions">
  56. <form method="POST">
  57. <?php echo csrfField(); ?>
  58. <input type="hidden" name="remove_product_id" value="<?php echo (int) $cartItem[
  59. "product"
  60. ]["id"]; ?>">
  61. <input type="hidden" name="remove_size" value="<?php echo escape(
  62. $cartItem["size"],
  63. ); ?>">
  64. <button type="submit" class="btn btn-secondary btn-small">Entfernen</button>
  65. </form>
  66. </div>
  67. </div>
  68. <?php endforeach; ?>
  69. <div class="cart-actions">
  70. <div class="cart-buttons">
  71. <a href="index.php" class="btn btn-secondary">Weiter auswählen</a>
  72. <a href="checkout.php" class="btn">Zur Bestellung</a>
  73. </div>
  74. </div>
  75. <?php endif; ?>
  76. <?php include __DIR__ . "/includes/footer.php"; ?>