checkout.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 class="list-indent">
  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 panel-compact">
  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. <?php if ($cartItem['availability_label'] !== ''): ?>
  48. Lieferhinweis: <?php echo escape($cartItem['availability_label']); ?>
  49. <?php endif; ?>
  50. </div>
  51. <?php endforeach; ?>
  52. </div>
  53. <div>
  54. <h3>Bestelldaten</h3>
  55. <form method="POST">
  56. <div class="form-group">
  57. <label for="customer_name">Name *</label>
  58. <input type="text" id="customer_name" name="customer_name" required value="<?php echo isset($_POST['customer_name']) ? escape($_POST['customer_name']) : ''; ?>">
  59. </div>
  60. <div class="form-group">
  61. <label for="customer_email">E-Mail-Adresse *</label>
  62. <input type="email" id="customer_email" name="customer_email" required value="<?php echo isset($_POST['customer_email']) ? escape($_POST['customer_email']) : ''; ?>">
  63. </div>
  64. <div class="form-group">
  65. <label for="organization_id">Organisation *</label>
  66. <select id="organization_id" name="organization_id" required>
  67. <option value="">Bitte wählen</option>
  68. <?php foreach ($organizations as $organization): ?>
  69. <option value="<?php echo escape($organization['id']); ?>" <?php echo (isset($_POST['organization_id']) && $_POST['organization_id'] === $organization['id']) ? 'selected' : ''; ?>>
  70. <?php echo escape($organization['label']); ?>
  71. </option>
  72. <?php endforeach; ?>
  73. </select>
  74. </div>
  75. <div class="form-group">
  76. <label for="comment">Kommentar</label>
  77. <textarea id="comment" name="comment" rows="5"><?php echo isset($_POST['comment']) ? escape($_POST['comment']) : ''; ?></textarea>
  78. </div>
  79. <div class="alert alert-info">
  80. <?php if (isOrderConfirmationRequired()): ?>
  81. Nach dem Absenden erhalten Sie eine E-Mail mit einem Bestätigungslink. Erst danach wird die Bestellung intern weitergeleitet.
  82. <?php else: ?>
  83. Nach dem Absenden wird die Bestellung direkt intern weitergeleitet.
  84. <?php endif; ?>
  85. </div>
  86. <button type="submit" name="create_order" class="btn btn-block">Bestellung absenden</button>
  87. </form>
  88. <div class="mt-2">
  89. <a href="cart.php" class="btn btn-secondary">Zurück zum Warenkorb</a>
  90. </div>
  91. </div>
  92. </div>
  93. <?php include __DIR__ . '/includes/footer.php'; ?>