shop + cart + user login with school
This commit is contained in:
@@ -1,12 +1,26 @@
|
||||
<?php include('include/headscript.php'); ?>
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
|
||||
// Ottieni l'istanza del DBHandlerSelect
|
||||
$dbHandler = DBHandlerSelect::getInstance();
|
||||
$pdo = $dbHandler->getConnection();
|
||||
|
||||
// Recupera lo school_id dalla sessione
|
||||
$school_id = session('school_id');
|
||||
|
||||
$school = null;
|
||||
$school_name = 'Nessuna scuola selezionata';
|
||||
$school_logo_path = url('userarea/photoschool/yogibook_logo.png'); // Default logo
|
||||
if ($school_id) {
|
||||
$school = \Vanguard\Models\School::find($school_id);
|
||||
if ($school) {
|
||||
$school_name = $school->name;
|
||||
$school_logo_path = $school->logo ? url('userarea/photoschool/' . $school->logo) : $school_logo_path;
|
||||
}
|
||||
}
|
||||
|
||||
$product_id = $_GET['product_id'] ?? 0;
|
||||
|
||||
// Recupera i dettagli del prodotto
|
||||
// Recupera i dettagli del prodotto, verificando che appartenga alla scuola selezionata
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT p.id, p.name AS product_name,
|
||||
c.name AS class_name, c.description AS class_description, c.photo AS class_photo
|
||||
@@ -14,14 +28,14 @@ $stmt = $pdo->prepare("
|
||||
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.id = ?
|
||||
WHERE p.id = ? AND p.school_id = ?
|
||||
GROUP BY p.id
|
||||
");
|
||||
$stmt->execute([$product_id]);
|
||||
$stmt->execute([$product_id, $school_id]);
|
||||
$product = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$product) {
|
||||
die("Prodotto non trovato.");
|
||||
die("Prodotto non trovato o non appartiene alla scuola selezionata.");
|
||||
}
|
||||
|
||||
// Recupera le variazioni del prodotto
|
||||
@@ -43,16 +57,29 @@ $stmt = $pdo->prepare("
|
||||
$stmt->execute([$product_id]);
|
||||
$class_types = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Dettaglio Prodotto - <?php echo htmlspecialchars($product['product_name']); ?></title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<!--favicon-->
|
||||
<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
|
||||
<?php include('cssinclude.php'); ?>
|
||||
<?php include('siteinfo.php'); ?>
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
<style>
|
||||
.page-content {
|
||||
background-color: #f0f4f5;
|
||||
}
|
||||
|
||||
.card-pastel {
|
||||
background-color: rgb(149, 217, 248);
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
||||
border: none;
|
||||
}
|
||||
|
||||
.product-image {
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
@@ -60,58 +87,124 @@ $class_types = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.btn-pastel {
|
||||
background-color: rgb(148, 186, 204);
|
||||
border: none;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.btn-pastel:hover {
|
||||
background-color: rgb(155, 189, 221);
|
||||
}
|
||||
|
||||
h5,
|
||||
h6 {
|
||||
font-family: 'Poppins', sans-serif;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.price-display {
|
||||
font-size: 1.5rem;
|
||||
color: #28a745;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-family: 'Poppins', sans-serif;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.form-select {
|
||||
border: 1px solid #c8e6c9;
|
||||
}
|
||||
|
||||
.swal2-pastel {
|
||||
background-color: #f0f4f5;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.swal2-title {
|
||||
font-family: 'Poppins', sans-serif;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.swal2-content {
|
||||
font-family: 'Poppins', sans-serif;
|
||||
color: #333;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container mt-5">
|
||||
<h1 class="mb-4"><?php echo htmlspecialchars($product['product_name']); ?></h1>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<img src="<?php echo htmlspecialchars($product['class_photo'] ?: 'default_class_image.jpg'); ?>" alt="<?php echo htmlspecialchars($product['class_name']); ?>" class="product-image">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<h3><?php echo htmlspecialchars($product['class_name']); ?></h3>
|
||||
<p><?php echo htmlspecialchars($product['class_description']); ?></p>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="variation_select" class="form-label">Seleziona Variazione Prodotto:</label>
|
||||
<select id="variation_select" class="form-select">
|
||||
<option value="">-- Seleziona --</option>
|
||||
<?php foreach ($variations as $variation): ?>
|
||||
<option value="<?php echo $variation['id']; ?>" data-price="<?php echo $variation['price']; ?>">
|
||||
<?php echo htmlspecialchars($variation['name']); ?> (<?php echo $variation['price']; ?>€)
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<div class="wrapper">
|
||||
<?php include('include/navbar.php'); ?>
|
||||
<?php include('include/topbar.php'); ?>
|
||||
<div class="page-wrapper">
|
||||
<div class="page-content">
|
||||
<div class="card card-pastel radius-10 mb-4">
|
||||
<div class="card-body text-center">
|
||||
<?php if ($school): ?>
|
||||
<h5 class="mb-3">Dettagli Prodotto - Scuola: <?php echo htmlspecialchars($school_name); ?></h5>
|
||||
<img src="<?php echo $school_logo_path; ?>" alt="School Logo" style="max-height: 100px;">
|
||||
<?php else: ?>
|
||||
<h5 class="mb-3">Nessuna scuola selezionata</h5>
|
||||
<img src="<?php echo $school_logo_path; ?>" alt="Default Logo" style="max-height: 100px;">
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="class_type_select" class="form-label">Seleziona Variazione Classe:</label>
|
||||
<select id="class_type_select" class="form-select">
|
||||
<option value="">-- Seleziona --</option>
|
||||
<?php foreach ($class_types as $class_type): ?>
|
||||
<option value="<?php echo $class_type['id']; ?>">
|
||||
<?php echo htmlspecialchars($class_type['level'] . ' (' . $class_type['day_of_week'] . ')'); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<div class="card card-pastel radius-10">
|
||||
<div class="card-header">
|
||||
<div class="d-flex align-items-center">
|
||||
<div>
|
||||
<h6 class="mb-0"><?php echo htmlspecialchars($product['product_name']); ?></h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<img src="<?php echo htmlspecialchars($product['class_photo'] ?: 'default_class_image.jpg'); ?>" alt="<?php echo htmlspecialchars($product['class_name']); ?>" class="product-image">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<h5><?php echo htmlspecialchars($product['class_name']); ?></h5>
|
||||
<p><?php echo htmlspecialchars($product['class_description']); ?></p>
|
||||
<div class="mb-3">
|
||||
<label for="variation_select" class="form-label">Seleziona Variazione Prodotto:</label>
|
||||
<select id="variation_select" class="form-select">
|
||||
<option value="">-- Seleziona --</option>
|
||||
<?php foreach ($variations as $variation): ?>
|
||||
<option value="<?php echo $variation['id']; ?>" data-price="<?php echo $variation['price']; ?>">
|
||||
<?php echo htmlspecialchars($variation['name']); ?> (<?php echo $variation['price']; ?>€)
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="class_type_select" class="form-label">Seleziona Variazione Classe:</label>
|
||||
<select id="class_type_select" class="form-select">
|
||||
<option value="">-- Seleziona --</option>
|
||||
<?php foreach ($class_types as $class_type): ?>
|
||||
<option value="<?php echo $class_type['id']; ?>">
|
||||
<?php echo htmlspecialchars($class_type['level'] . ' (' . $class_type['day_of_week'] . ')'); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="price-display" id="price_display">Prezzo: -- €</div>
|
||||
<button id="add_to_cart" class="btn btn-pastel mt-3" disabled>Aggiungi al Carrello</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="price-display" id="price_display">Prezzo: -- €</div>
|
||||
|
||||
<button id="add_to_cart" class="btn btn-success mt-3" disabled>Aggiungi al Carrello</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="overlay toggle-icon"></div>
|
||||
<a href="javaScript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
|
||||
<?php include('jsinclude.php'); ?>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
const variationSelect = $('#variation_select');
|
||||
@@ -139,9 +232,64 @@ $class_types = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
addToCartButton.on('click', function() {
|
||||
const variationId = variationSelect.val();
|
||||
const classTypeId = classTypeSelect.val();
|
||||
alert(`Prodotto aggiunto al carrello!\nVariazione: ${variationSelect.find('option:selected').text()}\nClasse: ${classTypeSelect.find('option:selected').text()}`);
|
||||
// Qui puoi aggiungere una chiamata AJAX per aggiungere al carrello
|
||||
const variationText = variationSelect.find('option:selected').text();
|
||||
const classText = classTypeSelect.find('option:selected').text();
|
||||
|
||||
// Chiamata AJAX per aggiungere al carrello
|
||||
$.ajax({
|
||||
url: 'add_to_cart.php',
|
||||
method: 'POST',
|
||||
data: {
|
||||
product_id: <?php echo $product_id; ?>,
|
||||
variation_id: variationId,
|
||||
class_type_id: classTypeId,
|
||||
quantity: 1
|
||||
},
|
||||
success: function(response) {
|
||||
const result = JSON.parse(response);
|
||||
if (result.success) {
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Prodotto Aggiunto!',
|
||||
html: `
|
||||
<p><strong>Variazione:</strong> ${variationText}</p>
|
||||
<p><strong>Classe:</strong> ${classText}</p>
|
||||
`,
|
||||
confirmButtonText: 'OK',
|
||||
confirmButtonColor: '#94bacc',
|
||||
customClass: {
|
||||
popup: 'swal2-pastel',
|
||||
title: 'swal2-title',
|
||||
content: 'swal2-content'
|
||||
}
|
||||
}).then(() => {
|
||||
// Ricarica il conteggio del carrello nella topbar
|
||||
updateCartCount(result.cart_count);
|
||||
});
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Errore',
|
||||
text: 'Impossibile aggiungere il prodotto al carrello.',
|
||||
confirmButtonColor: '#94bacc'
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Errore',
|
||||
text: 'Errore di connessione.',
|
||||
confirmButtonColor: '#94bacc'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Funzione per aggiornare il conteggio del carrello nella topbar
|
||||
function updateCartCount(count) {
|
||||
$('.alert-count.cart-count').text(count);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user