From 279bdd615e0a2e8120dfe25b4cfa86785f69e337 Mon Sep 17 00:00:00 2001 From: Claudio Date: Mon, 14 Apr 2025 11:25:26 +0200 Subject: [PATCH] upd checkout --- public/userarea/checkout.php | 44 ++++++++++----- public/userarea/include/navbar.php | 50 +++++++---------- public/userarea/shop-school.php | 2 +- public/userarea/thank_you.php | 14 ++++- public/userarea/user_dashboard.php | 89 +++++++++++++++++++++++++++--- 5 files changed, 142 insertions(+), 57 deletions(-) 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) {
-
+
<?php echo htmlspecialchars($product['class_name']); ?>
diff --git a/public/userarea/thank_you.php b/public/userarea/thank_you.php index e0fd4e6..2256771 100644 --- a/public/userarea/thank_you.php +++ b/public/userarea/thank_you.php @@ -6,7 +6,13 @@ $pdo = $dbHandler->getConnection(); // Recupera lo school_id e user_id dalla sessione $school_id = session('school_id'); -$user_id = session('iduserlogin'); // Cambiato da 'user_id' a 'iduserlogin' +$user_id = $iduserlogin; + +// Controlla se l'utente è loggato +if (empty($user_id)) { + header('Location: login.php?error=not_logged_in'); + exit; +} // Recupera l'order_number dai parametri GET $order_number = $_GET['order_number'] ?? 0; @@ -27,7 +33,7 @@ $order_items = []; $total_price = 0; if ($order_number) { $stmt = $pdo->prepare(" - SELECT o.order_number, o.created_at, o.price, o.total_entries, o.available_entries, o.activation_date, + SELECT o.order_number, o.created_at, o.price, o.total_entries, o.available_entries, o.available_recoveries, o.expiration_date, o.activation_date, p.name AS product_name, pv.name AS variation_name, c.name AS class_name, ct.level, ct.day_of_week, c.photo AS class_photo FROM orders o JOIN products p ON o.product_id = p.id @@ -166,6 +172,10 @@ $order_date = $order_items[0]['created_at'];

Variazione:

Classe:

Entrate Totali:

+

Recuperi Disponibili:

+ +

Valido fino al:

+

Prezzo:

diff --git a/public/userarea/user_dashboard.php b/public/userarea/user_dashboard.php index 2697ca6..3debd9a 100644 --- a/public/userarea/user_dashboard.php +++ b/public/userarea/user_dashboard.php @@ -4,9 +4,16 @@ $dbHandler = DBHandlerSelect::getInstance(); $pdo = $dbHandler->getConnection(); -// Recupera lo school_id dalla sessione +// Recupera lo school_id e user_id dalla sessione $school_id = session('school_id'); + +// Controlla se l'utente è loggato +if (empty($iduserlogin)) { + header('Location: login.php?error=not_logged_in'); + exit; +} + $school = null; // Costruisci manualmente l'URL assoluto per il logo di default $base_url = rtrim(env('APP_URL'), '/') . '/public/userarea/'; @@ -26,6 +33,21 @@ $stmt->execute([$iduserlogin]); $user = $stmt->fetch(); // Dopo aver recuperato i dati dell'utente $avatar = !empty($user['avatar']) ? '../upload/users/' . $user['avatar'] : '../assets/images/default-avatar.png'; + +// Query per recuperare gli ordini dell'utente per la scuola corrente +$stmt = $pdo->prepare(" + SELECT o.order_number, o.created_at, o.price, o.total_entries, o.available_entries, o.available_recoveries, o.expiration_date, o.activation_date, + p.name AS product_name, pv.name AS variation_name, c.name AS class_name, ct.level, ct.day_of_week + FROM orders o + JOIN products p ON o.product_id = p.id + JOIN product_variations pv ON o.variation_id = pv.id + LEFT JOIN class_types ct ON o.class_type_id = ct.id + LEFT JOIN classes c ON ct.class_id = c.id + WHERE o.user_id = ? AND o.school_id = ? + ORDER BY o.created_at DESC +"); +$stmt->execute([$iduserlogin, $school_id]); +$orders = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> @@ -71,7 +93,8 @@ $avatar = !empty($user['avatar']) ? '../upload/users/' . $user['avatar'] : '../a /* Colore più scuro al passaggio del mouse */ } - h5 { + h5, + h6 { font-family: 'Poppins', sans-serif; /* Font moderno e morbido, se disponibile */ color: #333; @@ -89,14 +112,16 @@ $avatar = !empty($user['avatar']) ? '../upload/users/' . $user['avatar'] : '../a /* Spazio tra gli elementi */ } - .lesson-card { + .lesson-card, + .order-card { background-color: #ffffff; border-left: 4px solid #c8e6c9; - /* Verde per le lezioni programmate */ + /* Verde per le lezioni programmate e ordini */ transition: transform 0.2s ease; } - .lesson-card:hover { + .lesson-card:hover, + .order-card:hover { transform: translateY(-3px); } @@ -124,12 +149,19 @@ $avatar = !empty($user['avatar']) ? '../upload/users/' . $user['avatar'] : '../a border-radius: 15px; } - .lesson-details p { + .lesson-details p, + .order-details p { margin-bottom: 0.2rem; /* Spazio ridotto tra le righe */ font-size: 0.85rem; /* Testo più piccolo per adattarsi meglio */ } + + .order-details .price { + font-weight: bold; + color: #28a745; + /* Verde per il prezzo */ + } @@ -169,7 +201,6 @@ $avatar = !empty($user['avatar']) ? '../upload/users/' . $user['avatar'] : '../a
-
Ciao, !
@@ -265,6 +296,48 @@ $avatar = !empty($user['avatar']) ? '../upload/users/' . $user['avatar'] : '../a
+ +
+
+
+
+
I tuoi Ordini
+
+
+
+
+ +

Non hai ancora effettuato ordini per questa scuola.

+ +
+ +
+
+
+
+
Ordine #
+

Data:

+

Prodotto:

+

Variazione:

+ +

Classe:

+ +

Entrate Totali:

+

Recuperi Disponibili:

+ +

Valido fino al:

+ +

Prezzo:

+
+
+
+
+ +
+ +
+
+
@@ -278,13 +351,11 @@ $avatar = !empty($user['avatar']) ? '../upload/users/' . $user['avatar'] : '../a - -