0) { if (isset($_SESSION['cart'][$product_id])) {$_SESSION['cart'][$product_id] +=$qty; } else { $_SESSION['cart'][$product_id] =$qty; } } header("Location: cart.php"); exit; } if ($action === 'remove') {$product_id = isset($_GET['id']) ? (int)$_GET['id'] : 0; if (isset($_SESSION['cart'][$product_id])) { unset($_SESSION['cart'][$product_id]); } header("Location: cart.php"); exit; } // Δυναμική ανάγνωση ενεργού theme $active_theme = 'default'; try { $stmt =$pdo->query("SELECT value FROM settings WHERE `key` = 'active_theme'"); $res =$stmt->fetchColumn(); if ($res) { $active_theme =$res; } } catch (Exception $e) {} $theme_dir = __DIR__ . '/themes/' .$active_theme; if (!is_dir($theme_dir)) { $active_theme = 'default';$theme_dir = __DIR__ . '/themes/default'; } $loader = new \Twig\Loader\FilesystemLoader($theme_dir); $twig = new \Twig\Environment($loader, ['cache' => false]); $twig->addGlobal('session',$_SESSION); $twig->addGlobal('current_lang',$current_lang); // Διόρθωση: Ανάγνωση κατηγοριών με τα δίγλωσσα πεδία (name_el / name_en) try { $categoriesRaw =$pdo->query("SELECT * FROM categories ORDER BY sort_order ASC, name_el ASC")->fetchAll(PDO::FETCH_ASSOC); $categories = []; foreach ($categoriesRaw as $cat) {$cat['name'] = ($current_lang === 'en' && !empty($cat['name_en'])) ? $cat['name_en'] :$cat['name_el']; $categories[] =$cat; } } catch (Exception $e) {$categories = []; } // Φέρνουμε τα στοιχεία των προϊόντων που βρίσκονται στο καλάθι από τη βάση $cart_items = [];$total_price = 0; if (!empty($_SESSION['cart'])) { $ids = array_keys($_SESSION['cart']); $placeholders = implode(',', array_fill(0, count($ids), '?')); $stmt =$pdo->prepare(" SELECT p.id, p.title, p.price, pi.image_path FROM products p LEFT JOIN product_images pi ON (p.id = pi.product_id AND pi.is_primary = 1) WHERE p.id IN ($placeholders) "); $stmt->execute($ids); $products_in_db =$stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($products_in_db as$prod) { $prod_id =$prod['id']; $qty =$_SESSION['cart'][$prod_id];$subtotal = $prod['price'] *$qty; $total_price +=$subtotal; $cart_items[] = [ 'id' => $prod_id, 'title' => $prod['title'], 'price' => $prod['price'], 'image_path' => $prod['image_path'], 'quantity' => $qty, 'subtotal' => $subtotal ]; } } echo $twig->render('cart.html.twig', [ 'site_title' => 'Hockey Gear CMS', 'categories' => $categories, 'cart_items' => $cart_items, 'total_price' => $total_price ]);