Checkout - Scuola:
+Nessuna scuola selezionata
+Riepilogo Carrello
+Il carrello è vuoto.
+ +Variazione:
+Classe:
+Quantità:
+Prezzo Unitario: €
+Subtotale: €
+diff --git a/.env b/.env index 5f83bcd..3a96daf 100644 --- a/.env +++ b/.env @@ -1,7 +1,7 @@ APP_ENV=production -APP_DEBUG=false +APP_DEBUG=true APP_KEY=base64:RWTN8ZDkeItU6xmobXjl6sRn8ph0XoAHgDpX4+wCdlE= -APP_URL=http://vanguard.test +APP_URL=http://localhost/yogiboook LOG_CHANNEL=stack diff --git a/app/Http/Controllers/Web/Auth/LoginController.php b/app/Http/Controllers/Web/Auth/LoginController.php index cf40d2c..7d8e042 100644 --- a/app/Http/Controllers/Web/Auth/LoginController.php +++ b/app/Http/Controllers/Web/Auth/LoginController.php @@ -16,6 +16,7 @@ use Vanguard\Repositories\Session\SessionRepository; use Vanguard\Repositories\User\UserRepository; use Vanguard\Services\Auth\ThrottlesLogins; use Vanguard\User; +use Vanguard\Models\School; class LoginController extends Controller { @@ -30,32 +31,58 @@ class LoginController extends Controller /** * Show the application login form. */ - public function show(): View + public function show($school = null): View { + // Debug: aggiungiamo un log per verificare se arriviamo qui + \Log::info('LoginController::show chiamato con school = ' . ($school ?? 'null')); + + // Cerca la scuola in base allo slug + $schoolData = null; + if ($school) { + $schoolData = School::where('slug', $school)->first(); + } + return view('auth.login', [ 'socialProviders' => config('auth.social.providers'), + 'school_slug' => $school, + 'school_logo' => $schoolData ? $schoolData->logo : null, ]); } public function login(LoginRequest $request, SessionRepository $sessions): Response|RedirectResponse { + // Debug: aggiungiamo un log per verificare se arriviamo qui + \Log::info('LoginController::login chiamato con input: ' . json_encode($request->all())); + // In case that request throttling is enabled, we have to check if user can perform this request. - // We'll key this by the username and the IP address of the client making these requests into this application. $throttles = (bool) setting('throttle_enabled'); - //Redirect URL that can be passed as hidden field. + // Redirect URL that can be passed as hidden field. $to = $request->has('to') ? '?to=' . $request->get('to') : ''; if ($throttles && $this->hasTooManyLoginAttempts($request)) { return $this->sendLockoutResponse($request); } + // Validazione del campo school + $schoolSlug = $request->input('school'); + if ($schoolSlug) { + $school = School::where('slug', $schoolSlug)->first(); + if (!$school) { + return redirect()->to('login' . $to) + ->withErrors(['school' => trans('auth.school_not_found')]); + } + // Salva lo school_id nella sessione + $request->session()->put('school_id', $school->id); + } else { + // Se il campo school è vuoto, possiamo gestire il caso di default + return redirect()->to('login' . $to) + ->withErrors(['school' => trans('auth.school_required')]); + } + $credentials = $request->getCredentials(); if (! Auth::validate($credentials)) { - // If the login attempt was unsuccessful we will increment the number of attempts - // to log in and redirect the user back to the login form. Of course, when this - // user surpasses their maximum number of attempts they will get locked out. if ($throttles) { $this->incrementLoginAttempts($request); } @@ -94,7 +121,7 @@ class LoginController extends Controller $this->clearLoginAttempts($request); } - // Redirezione basata sul ruolo con la prima lettera maiuscola e prefisso 'userarea/' + // Redirezione basata sul ruolo if ($user->hasRole('Admin')) { return redirect()->to('userarea/admin.php'); } elseif ($user->hasRole('User')) { @@ -105,11 +132,9 @@ class LoginController extends Controller return redirect()->to('userarea/school_dashboard.php'); } - // Fallback nel caso il ruolo non corrisponda return redirect()->intended('userarea/default.php'); } - protected function logoutAndRedirectToTokenPage(Request $request, $user, ?string $redirectPage): RedirectResponse { Auth::logout(); diff --git a/app/Models/School.php b/app/Models/School.php new file mode 100644 index 0000000..ebd6935 --- /dev/null +++ b/app/Models/School.php @@ -0,0 +1,33 @@ + env('MYSQL_ATTR_SSL_CA'), ]) : [], ], - + 'mysql_no_prefix' => [ + 'driver' => 'mysql', + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', '3306'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', // Nessun prefisso per questa connessione + 'prefix_indexes' => true, + 'strict' => true, + 'engine' => null, + ], 'mariadb' => [ 'driver' => 'mariadb', 'url' => env('DB_URL'), @@ -154,7 +167,7 @@ return [ 'options' => [ 'cluster' => env('REDIS_CLUSTER', 'redis'), - 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'), + 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_') . '_database_'), ], 'default' => [ diff --git a/config/fortify.php b/config/fortify.php index 35577d6..d82513e 100644 --- a/config/fortify.php +++ b/config/fortify.php @@ -86,7 +86,7 @@ return [ | */ - 'prefix' => '', + 'prefix' => 'auth', 'domain' => null, diff --git a/public/userarea/add_to_cart.php b/public/userarea/add_to_cart.php new file mode 100644 index 0000000..cc0fb35 --- /dev/null +++ b/public/userarea/add_to_cart.php @@ -0,0 +1,40 @@ + false, 'message' => 'Dati non validi']); + exit; +} + +// Chiave univoca per l'elemento nel carrello +$cart_key = $product_id . '-' . $variation_id . '-' . $class_type_id; + +// Aggiungi o aggiorna il prodotto nel carrello +if (isset($_SESSION['cart'][$cart_key])) { + $_SESSION['cart'][$cart_key]['quantity'] += $quantity; +} else { + $_SESSION['cart'][$cart_key] = [ + 'product_id' => $product_id, + 'variation_id' => $variation_id, + 'class_type_id' => $class_type_id, + 'quantity' => $quantity + ]; +} + +// Calcola il numero totale di elementi nel carrello +$cart_count = array_sum(array_column($_SESSION['cart'], 'quantity')); + +// Rispondi con successo +echo json_encode(['success' => true, 'cart_count' => $cart_count]); diff --git a/public/userarea/checkout.php b/public/userarea/checkout.php new file mode 100644 index 0000000..6802604 --- /dev/null +++ b/public/userarea/checkout.php @@ -0,0 +1,358 @@ +getConnection(); + +// Recupera lo school_id e user_id dalla sessione +$school_id = session('school_id'); +$user_id = $iduserlogin; + +// Debug: verifica il valore di iduserlogin +\Log::info('Valore di iduserlogin: ' . $user_id); + +// Controlla se l'utente è loggato +if (empty($user_id)) { + // Reindirizza alla pagina di login se l'utente non è loggato + header('Location: login.php?error=not_logged_in'); + exit; +} + +$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; + } +} + +// Inizializza il carrello se non esiste +if (!isset($_SESSION['cart'])) { + $_SESSION['cart'] = []; +} + +// Recupera i prodotti nel carrello +$cart_items = []; +$total_price = 0; +if (!empty($_SESSION['cart'])) { + foreach ($_SESSION['cart'] as $cart_key => $item) { + $product_id = $item['product_id']; + $variation_id = $item['variation_id']; + $class_type_id = $item['class_type_id']; + $quantity = $item['quantity']; + + // 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, + ct.id AS class_type_id, ct.level, ct.day_of_week + FROM products p + JOIN product_variations pv ON pv.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 ct.id = ? + LEFT JOIN classes c ON ct.class_id = c.id + WHERE p.id = ? + "); + $stmt->execute([$variation_id, $class_type_id, $product_id]); + $cart_item = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($cart_item) { + $cart_items[$cart_key] = [ + 'product_id' => $cart_item['product_id'], + 'product_name' => $cart_item['product_name'], + 'variation_id' => $cart_item['variation_id'], + 'variation_name' => $cart_item['variation_name'], + 'class_id' => $cart_item['class_id'], + 'class_name' => $cart_item['class_name'], + 'class_type_id' => $cart_item['class_type_id'], + 'level' => $cart_item['level'], + 'day_of_week' => $cart_item['day_of_week'], + 'photo' => $cart_item['class_photo'] ?: 'default_class_image.jpg', + 'price' => $cart_item['price'], + 'quantity' => $quantity, + 'subtotal' => $cart_item['price'] * $quantity + ]; + $total_price += $cart_item['price'] * $quantity; + } + } +} + +// Calcola il numero totale di elementi nel carrello +$cart_count = array_sum(array_column($_SESSION['cart'], 'quantity')); + +// Gestione della conferma dell'acquisto +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['confirm_purchase'])) { + // Assicurati che non ci siano output prima di questo punto + ob_start(); // Avvia il buffer per catturare eventuali output indesiderati + + if (empty($cart_items)) { + $response = ['success' => false, 'message' => 'Il carrello è vuoto.']; + } else { + try { + // Verifica che user_id non sia NULL (dovrebbe essere già garantito dal controllo sopra) + if (empty($user_id)) { + throw new Exception("L'ID utente non è definito nella sessione."); + } + + // Genera un order_number unico + $stmt = $pdo->query("SELECT MAX(order_number) AS max_order FROM orders"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + $order_number = ($result['max_order'] ?? 0) + 1; + + // 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]; + } + $available_entries = $total_entries; + $available_recoveries = 0; // Da definire + $expiration_date = null; // Da definire + $activation_date = date('Y-m-d'); // Oggi + + $stmt = $pdo->prepare(" + INSERT INTO orders ( + order_number, school_id, user_id, product_id, variation_id, class_id, class_type_id, + created_at, payment_method, price, status, total_entries, available_entries, + available_recoveries, expiration_date, activation_date + ) VALUES (?, ?, ?, ?, ?, ?, ?, NOW(), 'direct', ?, 'completed', ?, ?, ?, ?, ?) + "); + $stmt->execute([ + $order_number, + $school_id, + $user_id, + $item['product_id'], + $item['variation_id'], + $item['class_id'], + $item['class_type_id'], + $item['subtotal'], + $total_entries, + $available_entries, + $available_recoveries, + $expiration_date, + $activation_date + ]); + } + + // Svuota il carrello + $_SESSION['cart'] = []; + + // Reindirizza alla pagina di ringraziamento con l'order_number + $response = ['success' => true, 'redirect' => 'thank_you.php?order_number=' . $order_number]; + } catch (Exception $e) { + $response = ['success' => false, 'message' => 'Errore durante l\'acquisto: ' . $e->getMessage()]; + } + } + + // Pulisci il buffer e invia la risposta JSON + ob_end_clean(); + header('Content-Type: application/json'); + echo json_encode($response); + exit; +} +?> + + + +
+ + + + + + + + + + +Il carrello è vuoto.
+ +Variazione:
+Classe:
+Quantità:
+Prezzo Unitario: €
+Subtotale: €
+You have recived new orders
-Many desktop publishing packages
-Successfully created new email
-Your new product has approved
-Making this the first true generator
-Successfully shipped your item
-24 new authors joined last week
-It was popularised in the 1960s
-
- Nessun prodotto disponibile per questa scuola.
+ +
+ + +
+ + Dettagli +Ordine effettuato il
+
+ Variazione:
+Classe:
+Entrate Totali:
+Prezzo: €
+15 Apr 2025, 18:00
+Scuola: Yoga Harmony
+Via Roma 12, Milano
+20 Apr 2025, 09:00
+Scuola: Zen Studio
+Corso Italia 45, Torino
+
+ @endif