| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- require_once __DIR__ . '/config.php';
- require_once __DIR__ . '/includes/functions.php';
- $pageTitle = 'Bestellung abschließen';
- $cartItems = getCartItemsDetailed();
- $organizations = getOrganizations(true);
- $errors = [];
- if (empty($cartItems)) {
- header('Location: cart.php');
- exit;
- }
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['create_order'])) {
- $customerName = $_POST['customer_name'] ?? '';
- $customerEmail = $_POST['customer_email'] ?? '';
- $organizationId = $_POST['organization_id'] ?? '';
- $comment = $_POST['comment'] ?? '';
- $result = createOrder($customerName, $customerEmail, $organizationId, $comment, buildOrderItemsFromCart());
- if (!$result['success']) {
- $errors[] = $result['message'];
- } else {
- clearCart();
- header('Location: order-success.php?id=' . urlencode($result['order']['id']));
- exit;
- }
- }
- include __DIR__ . '/includes/header.php';
- ?>
- <h2>Bestellung abschließen</h2>
- <?php if (!empty($errors)): ?>
- <div class="alert alert-error">
- <ul class="list-indent">
- <?php foreach ($errors as $error): ?>
- <li><?php echo escape($error); ?></li>
- <?php endforeach; ?>
- </ul>
- </div>
- <?php endif; ?>
- <div class="checkout-grid">
- <div>
- <h3>Ihre Auswahl</h3>
- <?php foreach ($cartItems as $cartItem): ?>
- <div class="panel panel-compact">
- <strong><?php echo escape($cartItem['product']['name']); ?></strong><br>
- <?php if ($cartItem['size'] !== ''): ?>
- Größe: <?php echo escape($cartItem['size']); ?><br>
- <?php endif; ?>
- <?php if ($cartItem['availability_label'] !== ''): ?>
- Lieferhinweis: <?php echo escape($cartItem['availability_label']); ?>
- <?php endif; ?>
- </div>
- <?php endforeach; ?>
- </div>
- <div>
- <h3>Bestelldaten</h3>
- <form method="POST">
- <div class="form-group">
- <label for="customer_name">Name *</label>
- <input type="text" id="customer_name" name="customer_name" required value="<?php echo isset($_POST['customer_name']) ? escape($_POST['customer_name']) : ''; ?>">
- </div>
- <div class="form-group">
- <label for="customer_email">E-Mail-Adresse *</label>
- <input type="email" id="customer_email" name="customer_email" required value="<?php echo isset($_POST['customer_email']) ? escape($_POST['customer_email']) : ''; ?>">
- </div>
- <div class="form-group">
- <label for="organization_id">Organisation *</label>
- <select id="organization_id" name="organization_id" required>
- <option value="">Bitte wählen</option>
- <?php foreach ($organizations as $organization): ?>
- <option value="<?php echo escape($organization['id']); ?>" <?php echo (isset($_POST['organization_id']) && $_POST['organization_id'] === $organization['id']) ? 'selected' : ''; ?>>
- <?php echo escape($organization['label']); ?>
- </option>
- <?php endforeach; ?>
- </select>
- </div>
- <div class="form-group">
- <label for="comment">Kommentar</label>
- <textarea id="comment" name="comment" rows="5"><?php echo isset($_POST['comment']) ? escape($_POST['comment']) : ''; ?></textarea>
- </div>
- <div class="alert alert-info">
- <?php if (isOrderConfirmationRequired()): ?>
- Nach dem Absenden erhalten Sie eine E-Mail mit einem Bestätigungslink. Erst danach wird die Bestellung intern weitergeleitet.
- <?php else: ?>
- Nach dem Absenden wird die Bestellung direkt intern weitergeleitet.
- <?php endif; ?>
- </div>
- <button type="submit" name="create_order" class="btn btn-block">Bestellung absenden</button>
- </form>
- <div class="mt-2">
- <a href="cart.php" class="btn btn-secondary">Zurück zum Warenkorb</a>
- </div>
- </div>
- </div>
- <?php include __DIR__ . '/includes/footer.php'; ?>
|