88 lines
3.2 KiB
Plaintext

<?php
include('include/headscript.php');
$dbHandler = DBHandlerSelect::getInstance();
$pdo = $dbHandler->getConnection();
// Recupera i prodotti con le variazioni e le classi associate
$stmt = $pdo->prepare("
SELECT p.id, p.name AS product_name,
MIN(pv.price) AS min_price,
MAX(pv.price) AS max_price,
c.name AS class_name,
c.image AS class_image
FROM products p
LEFT JOIN product_variations pv ON p.id = pv.product_id
LEFT JOIN product_class_types pct ON p.id = pct.product_id AND pct.variation_id IS NULL
LEFT JOIN class_types ct ON pct.class_type_id = ct.id
LEFT JOIN classes c ON ct.class_id = c.id
WHERE p.status = 'active'
GROUP BY p.id
");
$stmt->execute();
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shop - Yogiboook</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.product-card {
border: 1px solid #ddd;
border-radius: 8px;
overflow: hidden;
transition: transform 0.2s;
}
.product-card:hover {
transform: scale(1.05);
}
.product-card img {
width: 100%;
height: 200px;
object-fit: cover;
}
.product-card .card-body {
padding: 15px;
text-align: center;
}
.product-card .price-range {
font-size: 1.1rem;
color: #28a745;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container mt-5">
<h1 class="text-center mb-4">Acquista un Prodotto</h1>
<div class="row">
<?php foreach ($products as $product): ?>
<div class="col-md-4 mb-4">
<div class="product-card">
<img src="<?php echo htmlspecialchars($product['class_image'] ?: 'default_class_image.jpg'); ?>" alt="<?php echo htmlspecialchars($product['class_name']); ?>">
<div class="card-body">
<h5 class="card-title"><?php echo htmlspecialchars($product['product_name']); ?></h5>
<p class="price-range">
<?php
if ($product['min_price'] == $product['max_price']) {
echo htmlspecialchars($product['min_price']) . '€';
} else {
echo htmlspecialchars($product['min_price']) . '€ - ' . htmlspecialchars($product['max_price']) . '€';
}
?>
</p>
<a href="product_detail.php?product_id=<?php echo $product['id']; ?>" class="btn btn-primary">Dettagli</a>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>