added shop example with variation
This commit is contained in:
parent
f8ad1c2210
commit
296d7dbb2a
@ -102,7 +102,7 @@ class LoginController extends Controller
|
|||||||
} elseif ($user->hasRole('teacher')) {
|
} elseif ($user->hasRole('teacher')) {
|
||||||
return redirect()->to('userarea/teacher.php');
|
return redirect()->to('userarea/teacher.php');
|
||||||
} elseif ($user->hasRole('school_owner')) {
|
} elseif ($user->hasRole('school_owner')) {
|
||||||
return redirect()->to('userarea/school.php');
|
return redirect()->to('userarea/school_dashboard.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback nel caso il ruolo non corrisponda
|
// Fallback nel caso il ruolo non corrisponda
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
include('include/headscript.php');
|
include('include/headscript.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$dbHandler = DBHandlerSelect::getInstance();
|
$dbHandler = DBHandlerSelect::getInstance();
|
||||||
$pdo = $dbHandler->getConnection();
|
$pdo = $dbHandler->getConnection();
|
||||||
|
|
||||||
// Verifica che iduserlogin sia definito
|
// Verifica che iduserlogin sia definito
|
||||||
if (!isset($iduserlogin)) {
|
if (!isset($iduserlogin)) {
|
||||||
die("Errore: ID utente non definito.");
|
http_response_code(400);
|
||||||
|
echo json_encode(['error' => 'ID utente non definito']);
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recupera i dati della scuola in base all'utente loggato
|
// Recupera i dati della scuola in base all'utente loggato
|
||||||
@ -20,22 +20,80 @@ $stmt = $pdo->prepare("
|
|||||||
$stmt->execute([$iduserlogin]);
|
$stmt->execute([$iduserlogin]);
|
||||||
$school = $stmt->fetch();
|
$school = $stmt->fetch();
|
||||||
if (!$school) {
|
if (!$school) {
|
||||||
die("Errore: Nessuna scuola trovata per l'utente loggato.");
|
http_response_code(404);
|
||||||
|
echo json_encode(['error' => 'Nessuna scuola trovata per l\'utente loggato']);
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
$school_id = $school['id'];
|
$school_id = $school['id'];
|
||||||
|
|
||||||
$product_id = $_GET['product_id'] ?? 0;
|
$product_id = $_GET['product_id'] ?? 0;
|
||||||
|
$variation_id = $_GET['variation_id'] ?? 0;
|
||||||
|
|
||||||
// Verifica che il prodotto appartenga alla scuola
|
if ($product_id <= 0) {
|
||||||
$stmt = $pdo->prepare("SELECT id FROM products WHERE id = ? AND school_id = ?");
|
http_response_code(400);
|
||||||
$stmt->execute([$product_id, $school_id]);
|
echo json_encode(['error' => 'ID prodotto non valido']);
|
||||||
if (!$stmt->fetch()) {
|
exit;
|
||||||
die("Errore: Prodotto non trovato o non autorizzato.");
|
}
|
||||||
|
|
||||||
|
// Recupera i dettagli del prodotto (inclusi is_full_access e auto_propagate_to_order)
|
||||||
|
$stmt = $pdo->prepare("
|
||||||
|
SELECT id, is_full_access, auto_propagate_to_order
|
||||||
|
FROM products
|
||||||
|
WHERE id = ? AND school_id = ?
|
||||||
|
");
|
||||||
|
$stmt->execute([$product_id, $school_id]);
|
||||||
|
$product = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
if (!$product) {
|
||||||
|
http_response_code(404);
|
||||||
|
echo json_encode(['error' => 'Prodotto non trovato o non autorizzato']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inizializza l'array di risposta con i dettagli del prodotto
|
||||||
|
$response = [
|
||||||
|
'is_full_access' => $product['is_full_access'],
|
||||||
|
'auto_propagate_to_order' => $product['auto_propagate_to_order'],
|
||||||
|
'class_types' => []
|
||||||
|
];
|
||||||
|
|
||||||
|
// Se variation_id è specificato, recupera i dettagli della variazione
|
||||||
|
if ($variation_id > 0) {
|
||||||
|
$stmt = $pdo->prepare("
|
||||||
|
SELECT id, auto_propagate_to_order
|
||||||
|
FROM product_variations
|
||||||
|
WHERE id = ? AND product_id = ?
|
||||||
|
");
|
||||||
|
$stmt->execute([$variation_id, $product_id]);
|
||||||
|
$variation = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
if (!$variation) {
|
||||||
|
http_response_code(404);
|
||||||
|
echo json_encode(['error' => 'Variazione non trovata o non autorizzata']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
// Sovrascrivi auto_propagate_to_order con il valore della variazione
|
||||||
|
$response['auto_propagate_to_order'] = $variation['auto_propagate_to_order'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recupera le classi associate
|
||||||
|
if ($variation_id > 0) {
|
||||||
|
$stmt = $pdo->prepare("
|
||||||
|
SELECT class_type_id
|
||||||
|
FROM product_class_types
|
||||||
|
WHERE product_id = ? AND variation_id = ?
|
||||||
|
");
|
||||||
|
$stmt->execute([$product_id, $variation_id]);
|
||||||
|
} else {
|
||||||
|
$stmt = $pdo->prepare("
|
||||||
|
SELECT class_type_id
|
||||||
|
FROM product_class_types
|
||||||
|
WHERE product_id = ? AND variation_id IS NULL
|
||||||
|
");
|
||||||
|
$stmt->execute([$product_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = $pdo->prepare("SELECT class_type_id FROM product_class_types WHERE product_id = ?");
|
|
||||||
$stmt->execute([$product_id]);
|
|
||||||
$class_types = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
$class_types = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
$response['class_types'] = $class_types;
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
echo json_encode($class_types);
|
echo json_encode($response);
|
||||||
|
exit;
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 300 KiB |
149
public/userarea/product_detail.php
Normal file
149
public/userarea/product_detail.php
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
include('include/headscript.php');
|
||||||
|
|
||||||
|
$dbHandler = DBHandlerSelect::getInstance();
|
||||||
|
$pdo = $dbHandler->getConnection();
|
||||||
|
|
||||||
|
$product_id = $_GET['product_id'] ?? 0;
|
||||||
|
|
||||||
|
// Recupera i dettagli del prodotto
|
||||||
|
$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
|
||||||
|
FROM products p
|
||||||
|
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 = ?
|
||||||
|
GROUP BY p.id
|
||||||
|
");
|
||||||
|
$stmt->execute([$product_id]);
|
||||||
|
$product = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if (!$product) {
|
||||||
|
die("Prodotto non trovato.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recupera le variazioni del prodotto
|
||||||
|
$stmt = $pdo->prepare("
|
||||||
|
SELECT id, name, price
|
||||||
|
FROM product_variations
|
||||||
|
WHERE product_id = ? AND status = 'active'
|
||||||
|
");
|
||||||
|
$stmt->execute([$product_id]);
|
||||||
|
$variations = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
// Recupera le variazioni delle classi associate al prodotto
|
||||||
|
$stmt = $pdo->prepare("
|
||||||
|
SELECT ct.id, ct.level, ct.day_of_week
|
||||||
|
FROM product_class_types pct
|
||||||
|
JOIN class_types ct ON pct.class_type_id = ct.id
|
||||||
|
WHERE pct.product_id = ? AND pct.variation_id IS NULL
|
||||||
|
");
|
||||||
|
$stmt->execute([$product_id]);
|
||||||
|
$class_types = $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>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">
|
||||||
|
<style>
|
||||||
|
.product-image {
|
||||||
|
width: 100%;
|
||||||
|
height: 300px;
|
||||||
|
object-fit: cover;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.price-display {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
color: #28a745;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
</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>
|
||||||
|
|
||||||
|
<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-success mt-3" disabled>Aggiungi al Carrello</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<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');
|
||||||
|
const classTypeSelect = $('#class_type_select');
|
||||||
|
const priceDisplay = $('#price_display');
|
||||||
|
const addToCartButton = $('#add_to_cart');
|
||||||
|
|
||||||
|
function updatePriceAndButton() {
|
||||||
|
const selectedVariation = variationSelect.val();
|
||||||
|
const selectedClassType = classTypeSelect.val();
|
||||||
|
|
||||||
|
if (selectedVariation && selectedClassType) {
|
||||||
|
const price = variationSelect.find('option:selected').data('price');
|
||||||
|
priceDisplay.text(`Prezzo: ${price}€`);
|
||||||
|
addToCartButton.prop('disabled', false);
|
||||||
|
} else {
|
||||||
|
priceDisplay.text('Prezzo: -- €');
|
||||||
|
addToCartButton.prop('disabled', true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
variationSelect.on('change', updatePriceAndButton);
|
||||||
|
classTypeSelect.on('change', updatePriceAndButton);
|
||||||
|
|
||||||
|
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
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
File diff suppressed because it is too large
Load Diff
88
public/userarea/shop-php.txt
Normal file
88
public/userarea/shop-php.txt
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<?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>
|
||||||
95
public/userarea/shop.php
Normal file
95
public/userarea/shop.php
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<?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.photo AS class_photo
|
||||||
|
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_photo'] ?: '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>
|
||||||
Loading…
x
Reference in New Issue
Block a user