prepare("SELECT id FROM categories WHERE slug = ?"); $stmt->execute([$category_slug]); $cat_id = $stmt->fetchColumn(); if ($cat_id) { $where[] = "p.category_id = ?"; $params[] = $cat_id; } } $brand_slug = $_GET['brand'] ?? ''; if ($brand_slug) { $stmt = $db->prepare("SELECT id FROM brands WHERE slug = ?"); $stmt->execute([$brand_slug]); $brand_id = $stmt->fetchColumn(); if ($brand_id) { $where[] = "p.brand_id = ?"; $params[] = $brand_id; } } if (isset($_GET['featured']) && $_GET['featured'] == 1) { $where[] = "p.featured = 1"; } if (isset($_GET['best_seller']) && $_GET['best_seller'] == 1) { $where[] = "p.best_seller = 1"; } if (isset($_GET['new']) && $_GET['new'] == 1) { $where[] = "p.new_arrival = 1"; } if (isset($_GET['sale']) && $_GET['sale'] == 1) { $where[] = "p.sale_price > 0 AND p.sale_price < p.regular_price"; } $min_price = $_GET['min_price'] ?? 0; $max_price = $_GET['max_price'] ?? ''; if ($max_price) { $where[] = "p.regular_price >= ?"; $params[] = $min_price; $where[] = "p.regular_price <= ?"; $params[] = $max_price; } $where_clause = implode(' AND ', $where); // Sorting $sort = $_GET['sort'] ?? 'newest'; $order_by = match($sort) { 'price_low' => 'p.regular_price ASC', 'price_high' => 'p.regular_price DESC', 'name' => 'p.name ASC', 'popular' => 'p.views DESC', default => 'p.created_at DESC' }; // Pagination $page_num = max(1, intval($_GET['page'] ?? 1)); $per_page = 12; $offset = ($page_num - 1) * $per_page; // Get total $count_sql = "SELECT COUNT(*) FROM products p WHERE $where_clause"; $count_stmt = $db->prepare($count_sql); $count_stmt->execute($params); $total_products = $count_stmt->fetchColumn(); $total_pages = ceil($total_products / $per_page); // Get products $sql = "SELECT p.*, c.name as category_name, c.slug as category_slug, b.name as brand_name FROM products p LEFT JOIN categories c ON p.category_id = c.id LEFT JOIN brands b ON p.brand_id = b.id WHERE $where_clause ORDER BY $order_by LIMIT $per_page OFFSET $offset"; $stmt = $db->prepare($sql); $stmt->execute($params); $products = $stmt->fetchAll(); ?>

Shop

Filter by Price

$val): if (!in_array($key, ['min_price', 'max_price', 'page'])): ?>
-

Brands

    query("SELECT * FROM brands WHERE status = 1 ORDER BY name ASC")->fetchAll(); foreach ($brands as $b): ?>

Showing - of products

0): ?>
1): ?>

No products found

Try adjusting your filters or search terms

Browse All Products