checkout.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. require_once __DIR__ . '/config.php';
  3. require_once __DIR__ . '/includes/functions.php';
  4. $pageTitle = 'Bestellung abschließen';
  5. $cartItems = getCartItemsDetailed();
  6. $organizations = getOrganizations(true);
  7. $errors = [];
  8. if (empty($cartItems)) {
  9. header('Location: cart.php');
  10. exit;
  11. }
  12. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['create_order'])) {
  13. $customerName = $_POST['customer_name'] ?? '';
  14. $customerEmail = $_POST['customer_email'] ?? '';
  15. $organizationId = $_POST['organization_id'] ?? '';
  16. $comment = $_POST['comment'] ?? '';
  17. $result = createOrder($customerName, $customerEmail, $organizationId, $comment, buildOrderItemsFromCart());
  18. if (!$result['success']) {
  19. $errors[] = $result['message'];
  20. } else {
  21. clearCart();
  22. header('Location: order-success.php?id=' . urlencode($result['order']['id']));
  23. exit;
  24. }
  25. }
  26. include __DIR__ . '/includes/header.php';
  27. ?>
  28. <h2>Bestellung abschließen</h2>
  29. <?php if (!empty($errors)): ?>
  30. <div class="alert alert-error">
  31. <ul style="margin-left: 1.5rem;">
  32. <?php foreach ($errors as $error): ?>
  33. <li><?php echo escape($error); ?></li>
  34. <?php endforeach; ?>
  35. </ul>
  36. </div>
  37. <?php endif; ?>
  38. <div class="checkout-grid">
  39. <div>
  40. <h3>Ihre Auswahl</h3>
  41. <?php foreach ($cartItems as $cartItem): ?>
  42. <div class="panel" style="padding: 1rem; margin-bottom: 1rem;">
  43. <strong><?php echo escape($cartItem['product']['name']); ?></strong><br>
  44. <?php if ($cartItem['size'] !== ''): ?>
  45. Größe: <?php echo escape($cartItem['size']); ?><br>
  46. <?php endif; ?>
  47. Menge: 1<br>
  48. <?php if ($cartItem['availability_label'] !== ''): ?>
  49. Lieferhinweis: <?php echo escape($cartItem['availability_label']); ?>
  50. <?php endif; ?>
  51. </div>
  52. <?php endforeach; ?>
  53. </div>
  54. <div>
  55. <h3>Bestelldaten</h3>
  56. <form method="POST">
  57. <div class="form-group">
  58. <label for="customer_name">Name *</label>
  59. <input type="text" id="customer_name" name="customer_name" required value="<?php echo isset($_POST['customer_name']) ? escape($_POST['customer_name']) : ''; ?>">
  60. </div>
  61. <div class="form-group">
  62. <label for="customer_email">E-Mail-Adresse *</label>
  63. <input type="email" id="customer_email" name="customer_email" required value="<?php echo isset($_POST['customer_email']) ? escape($_POST['customer_email']) : ''; ?>">
  64. </div>
  65. <div class="form-group">
  66. <label for="organization_id">Organisation *</label>
  67. <select id="organization_id" name="organization_id" required>
  68. <option value="">Bitte wählen</option>
  69. <?php foreach ($organizations as $organization): ?>
  70. <option value="<?php echo escape($organization['id']); ?>" <?php echo (isset($_POST['organization_id']) && $_POST['organization_id'] === $organization['id']) ? 'selected' : ''; ?>>
  71. <?php echo escape($organization['label']); ?>
  72. </option>
  73. <?php endforeach; ?>
  74. </select>
  75. </div>
  76. <div class="form-group">
  77. <label for="comment">Kommentar</label>
  78. <textarea id="comment" name="comment" rows="5"><?php echo isset($_POST['comment']) ? escape($_POST['comment']) : ''; ?></textarea>
  79. </div>
  80. <div class="alert alert-info">
  81. <?php if (isOrderConfirmationRequired()): ?>
  82. Nach dem Absenden erhalten Sie eine E-Mail mit einem Bestätigungslink. Erst danach wird die Bestellung intern weitergeleitet.
  83. <?php else: ?>
  84. Nach dem Absenden wird die Bestellung direkt intern weitergeleitet.
  85. <?php endif; ?>
  86. </div>
  87. <button type="submit" name="create_order" class="btn" style="width: 100%;">Bestellung absenden</button>
  88. </form>
  89. <div style="margin-top: 1rem;">
  90. <a href="cart.php" class="btn btn-secondary">Zurück zum Warenkorb</a>
  91. </div>
  92. </div>
  93. </div>
  94. <?php include __DIR__ . '/includes/footer.php'; ?>