diff --git a/public/userarea/checkout.php b/public/userarea/checkout.php index 6802604..3861b68 100644 --- a/public/userarea/checkout.php +++ b/public/userarea/checkout.php @@ -52,7 +52,9 @@ if (!empty($_SESSION['cart'])) { // Query per ottenere i dettagli del prodotto, variazione e classe $stmt = $pdo->prepare(" - SELECT p.id AS product_id, p.name AS product_name, pv.id AS variation_id, pv.name AS variation_name, pv.price, c.id AS class_id, c.name AS class_name, c.photo AS class_photo, + SELECT p.id AS product_id, p.name AS product_name, + pv.id AS variation_id, pv.name AS variation_name, pv.price, pv.duration_days, pv.max_entries, pv.max_recoveries, + c.id AS class_id, c.name AS class_name, c.photo AS class_photo, ct.id AS class_type_id, ct.level, ct.day_of_week FROM products p JOIN product_variations pv ON pv.id = ? @@ -78,7 +80,10 @@ if (!empty($_SESSION['cart'])) { 'photo' => $cart_item['class_photo'] ?: 'default_class_image.jpg', 'price' => $cart_item['price'], 'quantity' => $quantity, - 'subtotal' => $cart_item['price'] * $quantity + 'subtotal' => $cart_item['price'] * $quantity, + 'duration_days' => $cart_item['duration_days'], + 'max_entries' => $cart_item['max_entries'], + 'max_recoveries' => $cart_item['max_recoveries'] ]; $total_price += $cart_item['price'] * $quantity; } @@ -97,7 +102,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['confirm_purchase'])) $response = ['success' => false, 'message' => 'Il carrello è vuoto.']; } else { try { - // Verifica che user_id non sia NULL (dovrebbe essere già garantito dal controllo sopra) + // Verifica che user_id non sia NULL if (empty($user_id)) { throw new Exception("L'ID utente non è definito nella sessione."); } @@ -109,14 +114,27 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['confirm_purchase'])) // Inserisci ogni elemento del carrello come un ordine foreach ($cart_items as $item) { - $total_entries = null; // Da calcolare in base alla variazione - if (preg_match('/(\d+) Ticket/i', $item['variation_name'], $matches)) { - $total_entries = (int)$matches[1]; - } + // Usa max_entries direttamente dalla tabella + $total_entries = $item['max_entries'] ?? 0; // 0 se non definito $available_entries = $total_entries; - $available_recoveries = 0; // Da definire - $expiration_date = null; // Da definire + + // Usa max_recoveries direttamente dalla tabella + $available_recoveries = $item['max_recoveries'] ?? 0; // 0 se non definito + + // Calcola expiration_date $activation_date = date('Y-m-d'); // Oggi + $expiration_date = null; + if (!empty($item['duration_days']) && is_numeric($item['duration_days'])) { + $expiration_date = date('Y-m-d', strtotime($activation_date . ' + ' . $item['duration_days'] . ' days')); + } + + // Debug: log dei valori + \Log::info('Calcolo expiration_date:', [ + 'variation_id' => $item['variation_id'], + 'duration_days' => $item['duration_days'], + 'activation_date' => $activation_date, + 'expiration_date' => $expiration_date + ]); $stmt = $pdo->prepare(" INSERT INTO orders ( @@ -318,12 +336,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['confirm_purchase'])) data: { confirm_purchase: true }, - dataType: 'json', // Specifica che ci aspettiamo JSON + dataType: 'json', success: function(response) { - // Non c'è bisogno di JSON.parse(), response è già un oggetto - console.log('Risposta AJAX:', response); // Debug + console.log('Risposta AJAX:', response); if (response.success) { - // Reindirizza alla pagina di ringraziamento window.location.href = response.redirect; } else { Swal.fire({ @@ -341,7 +357,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['confirm_purchase'])) } }, error: function(xhr, status, error) { - console.log('Errore AJAX:', xhr.responseText); // Debug + console.log('Errore AJAX:', xhr.responseText); Swal.fire({ icon: 'error', title: 'Errore', diff --git a/public/userarea/include/navbar.php b/public/userarea/include/navbar.php index b99fdbd..4574757 100644 --- a/public/userarea/include/navbar.php +++ b/public/userarea/include/navbar.php @@ -11,84 +11,72 @@
+ \ No newline at end of file diff --git a/public/userarea/shop-school.php b/public/userarea/shop-school.php index 33e5b41..3aa0259 100644 --- a/public/userarea/shop-school.php +++ b/public/userarea/shop-school.php @@ -148,7 +148,7 @@ if ($school_id) {
Variazione:
Classe:
Entrate Totali:
+Recuperi Disponibili:
+ +Valido fino al:
+Prezzo: €
Non hai ancora effettuato ordini per questa scuola.
+ +Data:
+Prodotto:
+Variazione:
+ +Classe:
+ +Entrate Totali:
+Recuperi Disponibili:
+ +Valido fino al:
+ +Prezzo: €
+