579 lines
26 KiB
Twig
579 lines
26 KiB
Twig
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?= $title ?></title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
|
<link href="https://cdn.jsdelivr.net/npm/lightbox2@2.11.4/dist/css/lightbox.min.css" rel="stylesheet">
|
|
<style>
|
|
.navbar {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
}
|
|
.product-gallery {
|
|
position: relative;
|
|
}
|
|
.main-image {
|
|
width: 100%;
|
|
height: 400px;
|
|
object-fit: cover;
|
|
border-radius: 0.5rem;
|
|
}
|
|
.thumbnail {
|
|
width: 80px;
|
|
height: 80px;
|
|
object-fit: cover;
|
|
border-radius: 0.25rem;
|
|
cursor: pointer;
|
|
border: 2px solid transparent;
|
|
transition: border-color 0.2s;
|
|
}
|
|
.thumbnail:hover,
|
|
.thumbnail.active {
|
|
border-color: #667eea;
|
|
}
|
|
.product-info {
|
|
background: #f8f9fa;
|
|
border-radius: 0.5rem;
|
|
padding: 2rem;
|
|
}
|
|
.price {
|
|
font-size: 2rem;
|
|
font-weight: bold;
|
|
color: #28a745;
|
|
}
|
|
.rating {
|
|
color: #ffc107;
|
|
}
|
|
.review-item {
|
|
border-left: 3px solid #667eea;
|
|
padding-left: 1rem;
|
|
margin-bottom: 1rem;
|
|
}
|
|
.related-product {
|
|
transition: transform 0.2s;
|
|
}
|
|
.related-product:hover {
|
|
transform: translateY(-5px);
|
|
}
|
|
.quantity-input {
|
|
width: 80px;
|
|
}
|
|
.wishlist-btn {
|
|
transition: all 0.2s;
|
|
}
|
|
.wishlist-btn.active {
|
|
color: #dc3545;
|
|
}
|
|
.variant-selector {
|
|
border: 2px solid #dee2e6;
|
|
border-radius: 0.25rem;
|
|
padding: 0.5rem;
|
|
margin: 0.25rem;
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
}
|
|
.variant-selector:hover,
|
|
.variant-selector.selected {
|
|
border-color: #667eea;
|
|
background-color: #f8f9fa;
|
|
}
|
|
.breadcrumb {
|
|
background: transparent;
|
|
padding: 0;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<!-- Navigation -->
|
|
<nav class="navbar navbar-expand-lg navbar-dark">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="/">
|
|
<i class="fas fa-shopping-cart me-2"></i>Webshop
|
|
</a>
|
|
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav me-auto">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="/">Startseite</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="/products">Produkte</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="/categories">Kategorien</a>
|
|
</li>
|
|
</ul>
|
|
|
|
<div class="d-flex align-items-center">
|
|
<div class="position-relative me-3">
|
|
<input type="text"
|
|
class="form-control"
|
|
id="searchInput"
|
|
placeholder="Produkte suchen...">
|
|
</div>
|
|
<a href="/cart" class="btn btn-outline-light position-relative me-2">
|
|
<i class="fas fa-shopping-cart"></i>
|
|
<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger" id="cartCount">
|
|
0
|
|
</span>
|
|
</a>
|
|
<a href="/wishlist" class="btn btn-outline-light position-relative me-2">
|
|
<i class="fas fa-heart"></i>
|
|
<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger" id="wishlistCount">
|
|
0
|
|
</span>
|
|
</a>
|
|
<?php if (isset($_SESSION['customer_id'])): ?>
|
|
<a href="/account" class="btn btn-outline-light">
|
|
<i class="fas fa-user"></i>
|
|
</a>
|
|
<?php else: ?>
|
|
<a href="/login" class="btn btn-outline-light">
|
|
<i class="fas fa-sign-in-alt"></i>
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<!-- Main Content -->
|
|
<div class="container mt-4">
|
|
<!-- Breadcrumb -->
|
|
<nav aria-label="breadcrumb">
|
|
<ol class="breadcrumb">
|
|
<li class="breadcrumb-item"><a href="/">Startseite</a></li>
|
|
<li class="breadcrumb-item"><a href="/categories">Kategorien</a></li>
|
|
<li class="breadcrumb-item"><a href="/category/<?= $product['category_id'] ?>"><?= htmlspecialchars($product['category_name']) ?></a></li>
|
|
<li class="breadcrumb-item active" aria-current="page"><?= htmlspecialchars($product['name']) ?></li>
|
|
</ol>
|
|
</nav>
|
|
|
|
<!-- Product Details -->
|
|
<div class="row">
|
|
<!-- Product Images -->
|
|
<div class="col-lg-6 mb-4">
|
|
<div class="product-gallery">
|
|
<div class="mb-3">
|
|
<img src="<?= htmlspecialchars($product['image']) ?>"
|
|
class="main-image"
|
|
id="mainImage"
|
|
alt="<?= htmlspecialchars($product['name']) ?>">
|
|
</div>
|
|
|
|
<?php if (!empty($productImages)): ?>
|
|
<div class="d-flex gap-2">
|
|
<?php foreach ($productImages as $index => $image): ?>
|
|
<img src="<?= htmlspecialchars($image['image_url']) ?>"
|
|
class="thumbnail <?= $index === 0 ? 'active' : '' ?>"
|
|
onclick="changeMainImage(this, '<?= htmlspecialchars($image['image_url']) ?>')"
|
|
alt="<?= htmlspecialchars($product['name']) ?>">
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Product Info -->
|
|
<div class="col-lg-6">
|
|
<div class="product-info">
|
|
<h1 class="h3 mb-3"><?= htmlspecialchars($product['name']) ?></h1>
|
|
|
|
<!-- Rating -->
|
|
<?php if ($ratingStats['total_reviews'] > 0): ?>
|
|
<div class="mb-3">
|
|
<div class="rating">
|
|
<?php for ($i = 1; $i <= 5; $i++): ?>
|
|
<i class="fas fa-star <?= $i <= $ratingStats['avg_rating'] ? 'text-warning' : 'text-muted' ?>"></i>
|
|
<?php endfor; ?>
|
|
<span class="ms-2 text-muted">
|
|
<?= number_format($ratingStats['avg_rating'], 1) ?>
|
|
(<?= $ratingStats['total_reviews'] ?> Bewertungen)
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="price mb-3">€<?= number_format($product['price'], 2, ',', '.') ?></div>
|
|
|
|
<p class="text-muted mb-4"><?= htmlspecialchars($product['description']) ?></p>
|
|
|
|
<!-- Product Variants -->
|
|
<?php if (!empty($productVariants)): ?>
|
|
<div class="mb-3">
|
|
<label class="form-label">Variante:</label>
|
|
<div class="d-flex flex-wrap">
|
|
<?php foreach ($productVariants as $variant): ?>
|
|
<div class="variant-selector"
|
|
onclick="selectVariant(<?= $variant['id'] ?>, '<?= htmlspecialchars($variant['name']) ?>', <?= $variant['price'] ?>)">
|
|
<?= htmlspecialchars($variant['name']) ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Add to Cart -->
|
|
<div class="row mb-3">
|
|
<div class="col-auto">
|
|
<label for="quantity" class="form-label">Menge:</label>
|
|
<input type="number"
|
|
class="form-control quantity-input"
|
|
id="quantity"
|
|
value="1"
|
|
min="1"
|
|
max="99">
|
|
</div>
|
|
<div class="col">
|
|
<label class="form-label"> </label>
|
|
<div class="d-grid">
|
|
<button class="btn btn-primary btn-lg add-to-cart"
|
|
data-product-id="<?= $product['id'] ?>"
|
|
data-product-name="<?= htmlspecialchars($product['name']) ?>">
|
|
<i class="fas fa-cart-plus me-2"></i>Zum Warenkorb hinzufügen
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Wishlist Button -->
|
|
<div class="mb-3">
|
|
<button class="btn btn-outline-danger wishlist-btn"
|
|
id="wishlistBtn"
|
|
data-product-id="<?= $product['id'] ?>"
|
|
onclick="toggleWishlist(<?= $product['id'] ?>)">
|
|
<i class="fas fa-heart me-2"></i>Zur Wunschliste
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Product Meta -->
|
|
<div class="row text-muted small">
|
|
<div class="col-6">
|
|
<i class="fas fa-tag me-1"></i>
|
|
Kategorie: <?= htmlspecialchars($product['category_name']) ?>
|
|
</div>
|
|
<div class="col-6">
|
|
<i class="fas fa-box me-1"></i>
|
|
Artikel-Nr: <?= $product['id'] ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Reviews Section -->
|
|
<?php if (!empty($reviews)): ?>
|
|
<div class="row mt-5">
|
|
<div class="col-12">
|
|
<h3 class="mb-4">
|
|
<i class="fas fa-star me-2"></i>
|
|
Kundenbewertungen
|
|
</h3>
|
|
|
|
<?php foreach ($reviews as $review): ?>
|
|
<div class="review-item">
|
|
<div class="d-flex justify-content-between align-items-start">
|
|
<div>
|
|
<div class="rating mb-1">
|
|
<?php for ($i = 1; $i <= 5; $i++): ?>
|
|
<i class="fas fa-star <?= $i <= $review['rating'] ? 'text-warning' : 'text-muted' ?>"></i>
|
|
<?php endfor; ?>
|
|
</div>
|
|
<h6 class="mb-1">
|
|
<?= htmlspecialchars($review['first_name'] . ' ' . $review['last_name']) ?>
|
|
</h6>
|
|
<p class="text-muted small mb-2">
|
|
<?= date('d.m.Y', strtotime($review['created_at'])) ?>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<?php if (!empty($review['comment'])): ?>
|
|
<p class="mb-0"><?= htmlspecialchars($review['comment']) ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Add Review Form -->
|
|
<?php if (isset($_SESSION['customer_id'])): ?>
|
|
<div class="row mt-4">
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="mb-0">
|
|
<i class="fas fa-edit me-2"></i>
|
|
Bewertung schreiben
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<form id="reviewForm">
|
|
<input type="hidden" name="product_id" value="<?= $product['id'] ?>">
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Bewertung:</label>
|
|
<div class="rating-input">
|
|
<?php for ($i = 5; $i >= 1; $i--): ?>
|
|
<input type="radio" name="rating" value="<?= $i ?>" id="star<?= $i ?>" class="d-none">
|
|
<label for="star<?= $i ?>" class="rating-star">
|
|
<i class="fas fa-star"></i>
|
|
</label>
|
|
<?php endfor; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="comment" class="form-label">Kommentar:</label>
|
|
<textarea class="form-control"
|
|
id="comment"
|
|
name="comment"
|
|
rows="3"
|
|
placeholder="Ihre Bewertung..."></textarea>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary">
|
|
<i class="fas fa-paper-plane me-2"></i>Bewertung senden
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Related Products -->
|
|
<?php if (!empty($relatedProducts)): ?>
|
|
<div class="row mt-5">
|
|
<div class="col-12">
|
|
<h3 class="mb-4">
|
|
<i class="fas fa-th-large me-2"></i>
|
|
Ähnliche Produkte
|
|
</h3>
|
|
|
|
<div class="row">
|
|
<?php foreach ($relatedProducts as $relatedProduct): ?>
|
|
<div class="col-md-3 mb-4">
|
|
<div class="card related-product h-100">
|
|
<img src="<?= htmlspecialchars($relatedProduct['image']) ?>"
|
|
class="card-img-top"
|
|
alt="<?= htmlspecialchars($relatedProduct['name']) ?>"
|
|
style="height: 200px; object-fit: cover;">
|
|
|
|
<div class="card-body d-flex flex-column">
|
|
<h6 class="card-title"><?= htmlspecialchars($relatedProduct['name']) ?></h6>
|
|
<p class="card-text text-muted small">
|
|
<?= htmlspecialchars($relatedProduct['category_name']) ?>
|
|
</p>
|
|
<p class="card-text flex-grow-1">
|
|
<?= htmlspecialchars(substr($relatedProduct['description'], 0, 80)) ?>...
|
|
</p>
|
|
<div class="d-flex justify-content-between align-items-center mt-auto">
|
|
<span class="h6 text-success mb-0">
|
|
€<?= number_format($relatedProduct['price'], 2, ',', '.') ?>
|
|
</span>
|
|
<a href="/product/<?= $relatedProduct['id'] ?>"
|
|
class="btn btn-outline-primary btn-sm">
|
|
<i class="fas fa-eye me-1"></i>Ansehen
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<!-- Toast for Cart Updates -->
|
|
<div class="toast-container position-fixed bottom-0 end-0 p-3">
|
|
<div id="cartToast" class="toast" role="alert">
|
|
<div class="toast-header">
|
|
<i class="fas fa-shopping-cart me-2"></i>
|
|
<strong class="me-auto">Warenkorb</strong>
|
|
<button type="button" class="btn-close" data-bs-dismiss="toast"></button>
|
|
</div>
|
|
<div class="toast-body" id="toastMessage">
|
|
Produkt wurde zum Warenkorb hinzugefügt
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/lightbox2@2.11.4/dist/js/lightbox.min.js"></script>
|
|
<script>
|
|
// Image gallery
|
|
function changeMainImage(thumbnail, imageUrl) {
|
|
document.getElementById('mainImage').src = imageUrl;
|
|
|
|
// Update active thumbnail
|
|
document.querySelectorAll('.thumbnail').forEach(thumb => {
|
|
thumb.classList.remove('active');
|
|
});
|
|
thumbnail.classList.add('active');
|
|
}
|
|
|
|
// Add to cart functionality
|
|
document.querySelectorAll('.add-to-cart').forEach(button => {
|
|
button.addEventListener('click', function() {
|
|
const productId = this.dataset.productId;
|
|
const productName = this.dataset.productName;
|
|
const quantity = document.getElementById('quantity').value;
|
|
|
|
fetch('/cart/add', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
product_id: productId,
|
|
quantity: parseInt(quantity)
|
|
})
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
// Update cart count
|
|
document.getElementById('cartCount').textContent = data.cart_count;
|
|
|
|
// Show toast
|
|
document.getElementById('toastMessage').textContent =
|
|
`${quantity}x ${productName} wurde zum Warenkorb hinzugefügt`;
|
|
new bootstrap.Toast(document.getElementById('cartToast')).show();
|
|
|
|
// Update button
|
|
this.innerHTML = '<i class="fas fa-check me-2"></i>Hinzugefügt';
|
|
this.classList.remove('btn-primary');
|
|
this.classList.add('btn-success');
|
|
this.disabled = true;
|
|
|
|
setTimeout(() => {
|
|
this.innerHTML = '<i class="fas fa-cart-plus me-2"></i>Zum Warenkorb hinzufügen';
|
|
this.classList.remove('btn-success');
|
|
this.classList.add('btn-primary');
|
|
this.disabled = false;
|
|
}, 2000);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Add to cart error:', error);
|
|
alert('Fehler beim Hinzufügen zum Warenkorb');
|
|
});
|
|
});
|
|
});
|
|
|
|
// Wishlist functionality
|
|
function toggleWishlist(productId) {
|
|
fetch('/product/wishlist', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
product_id: productId
|
|
})
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
const btn = document.getElementById('wishlistBtn');
|
|
const icon = btn.querySelector('i');
|
|
|
|
if (data.in_wishlist) {
|
|
btn.classList.add('active');
|
|
icon.className = 'fas fa-heart me-2';
|
|
} else {
|
|
btn.classList.remove('active');
|
|
icon.className = 'far fa-heart me-2';
|
|
}
|
|
|
|
// Update wishlist count
|
|
document.getElementById('wishlistCount').textContent = data.wishlist_count || 0;
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Wishlist error:', error);
|
|
alert('Fehler bei der Wunschliste');
|
|
});
|
|
}
|
|
|
|
// Review form
|
|
document.getElementById('reviewForm')?.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const formData = new FormData(this);
|
|
|
|
fetch('/product/review', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
alert('Bewertung erfolgreich gespeichert!');
|
|
location.reload();
|
|
} else {
|
|
alert('Fehler: ' + data.message);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Review error:', error);
|
|
alert('Fehler beim Speichern der Bewertung');
|
|
});
|
|
});
|
|
|
|
// Rating stars
|
|
document.querySelectorAll('.rating-star').forEach((star, index) => {
|
|
star.addEventListener('click', function() {
|
|
const rating = 5 - index;
|
|
document.querySelector(`input[name="rating"][value="${rating}"]`).checked = true;
|
|
|
|
// Update star display
|
|
document.querySelectorAll('.rating-star i').forEach((icon, i) => {
|
|
if (i <= index) {
|
|
icon.className = 'fas fa-star text-warning';
|
|
} else {
|
|
icon.className = 'fas fa-star text-muted';
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
// Variant selection
|
|
function selectVariant(variantId, variantName, variantPrice) {
|
|
// Update variant display
|
|
document.querySelectorAll('.variant-selector').forEach(selector => {
|
|
selector.classList.remove('selected');
|
|
});
|
|
event.target.classList.add('selected');
|
|
|
|
// Update price
|
|
document.querySelector('.price').textContent = '€' + variantPrice.toFixed(2).replace('.', ',');
|
|
|
|
// Update add to cart button
|
|
document.querySelector('.add-to-cart').dataset.variantId = variantId;
|
|
}
|
|
|
|
// Check if product is in wishlist on page load
|
|
<?php if (isset($_SESSION['customer_id'])): ?>
|
|
fetch('/product/wishlist/check/<?= $product['id'] ?>')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.in_wishlist) {
|
|
const btn = document.getElementById('wishlistBtn');
|
|
btn.classList.add('active');
|
|
btn.querySelector('i').className = 'fas fa-heart me-2';
|
|
}
|
|
});
|
|
<?php endif; ?>
|
|
</script>
|
|
</body>
|
|
</html> |