| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- require_once __DIR__ . '/config.php';
- require_once __DIR__ . '/includes/functions.php';
- $productId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
- $product = getProductById($productId);
- if ($product === null) {
- header('Location: index.php');
- exit;
- }
- $pageTitle = $product['name'];
- $sizes = getProductSizes($product);
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_to_cart'])) {
- $size = trim((string) ($_POST['size'] ?? ''));
- if (!empty($sizes) && ($size === '' || !in_array($size, $sizes, true))) {
- $error = 'Bitte wählen Sie eine Größe aus.';
- } elseif (!addCartItem($product['id'], $size)) {
- $error = 'Der Artikel konnte nicht in den Warenkorb gelegt werden.';
- } else {
- header('Location: cart.php');
- exit;
- }
- }
- include __DIR__ . '/includes/header.php';
- ?>
- <?php if (isset($error)): ?>
- <div class="alert alert-error">
- <?php echo escape($error); ?>
- </div>
- <?php endif; ?>
- <div class="product-detail-grid">
- <div>
- <?php if (!empty($product['image']) && file_exists(__DIR__ . '/assets/images/' . $product['image'])): ?>
- <img src="<?php echo escape(SITE_URL); ?>/assets/images/<?php echo escape($product['image']); ?>" alt="<?php echo escape($product['name']); ?>" style="width: 100%; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
- <?php else: ?>
- <div class="product-placeholder">Kein Bild verfügbar</div>
- <?php endif; ?>
- </div>
- <div>
- <h1><?php echo escape($product['name']); ?></h1>
- <div style="margin: 1.5rem 0 2rem;">
- <h3>Beschreibung</h3>
- <p style="margin-top: 0.5rem; line-height: 1.8;"><?php echo nl2br(escape($product['description'])); ?></p>
- </div>
- <form method="POST" style="margin-top: 2rem;">
- <?php if (!empty($sizes)): ?>
- <div class="form-group">
- <label for="size">Größe *</label>
- <select id="size" name="size" required style="width: 100%;" onchange="updateAvailabilityNotice()">
- <option value="">Bitte wählen</option>
- <?php foreach ($sizes as $sizeOption): ?>
- <?php $label = getAvailabilityLabel($product, $sizeOption); ?>
- <option value="<?php echo escape($sizeOption); ?>" data-label="<?php echo escape($label); ?>">
- <?php echo escape($sizeOption); ?><?php echo $label !== '' ? ' - ' . escape($label) : ''; ?>
- </option>
- <?php endforeach; ?>
- </select>
- </div>
- <div id="availabilityNotice" class="alert alert-warning" style="display: none;"></div>
- <?php endif; ?>
- <div class="alert alert-info">
- Jeder Artikel wird mit Menge 1 in den Warenkorb gelegt.
- </div>
- <button type="submit" name="add_to_cart" class="btn" style="width: 100%;">In den Warenkorb</button>
- </form>
- <?php if (!empty($sizes)): ?>
- <script>
- function updateAvailabilityNotice() {
- const sizeSelect = document.getElementById('size');
- const notice = document.getElementById('availabilityNotice');
- const selectedOption = sizeSelect.options[sizeSelect.selectedIndex];
- const text = selectedOption ? selectedOption.getAttribute('data-label') : '';
- if (text) {
- notice.textContent = text;
- notice.style.display = 'block';
- } else {
- notice.textContent = '';
- notice.style.display = 'none';
- }
- }
- </script>
- <?php endif; ?>
- <div style="margin-top: 2rem;">
- <a href="index.php" class="btn btn-secondary">Zurück zur Übersicht</a>
- </div>
- </div>
- </div>
- <?php include __DIR__ . '/includes/footer.php'; ?>
|