🤩 File Manager - Mr.X
PHP:
8.3.33
Server:
Apache
OS:
Linux 5.14.0-611.49.1.el9_7.x86_64
User:
websparkit
Navigate
Upload:
Upload
New File
New Folder
Editing:shop.php
<?php require_once __DIR__ . '/../includes/config.php'; require_once __DIR__ . '/../includes/db.php'; require_once __DIR__ . '/../includes/functions.php'; $page = 'shop'; $page_title = 'Shop All Products'; require_once '../includes/header.php'; require_once '../includes/navbar.php'; // Filters $where = ["p.status = 1"]; $params = []; $search = $_GET['search'] ?? ''; if ($search) { $where[] = "(p.name LIKE ? OR p.short_description LIKE ? OR p.tags LIKE ?)"; $params[] = "%$search%"; $params[] = "%$search%"; $params[] = "%$search%"; } $category_slug = $_GET['category'] ?? $_GET['slug'] ?? ''; if ($category_slug) { $stmt = $db->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(); ?> <main> <!-- Page Header --> <section class="page-header-section" style="background: var(--gradient-soft); padding: 60px 0; text-align: center;"> <div class="container"> <h1 style="font-size: 3rem; margin-bottom: 15px;">Shop</h1> <nav aria-label="breadcrumb"> <ol class="breadcrumb justify-content-center"> <li class="breadcrumb-item"><a href="<?= SITE_URL ?>">Home</a></li> <li class="breadcrumb-item active">Shop</li> <?php if ($search): ?> <li class="breadcrumb-item active">Search: "<?= htmlspecialchars($search) ?>"</li> <?php endif; ?> </ol> </nav> </div> </section> <!-- Shop Section --> <section class="shop-section" style="padding: 60px 0;"> <div class="container"> <div class="row g-4"> <!-- Sidebar Filters --> <div class="col-lg-3 col-md-4"> <div class="shop-sidebar" style="position: sticky; top: 100px;"> <!-- Categories --> <div class="filter-widget" style="background: var(--white); padding: 25px; border-radius: 16px; margin-bottom: 20px; box-shadow: var(--shadow-sm);"> <h4 style="font-size: 1.1rem; margin-bottom: 20px; font-family: var(--font-primary); font-weight: 600;">Categories</h4> <ul class="filter-list" style="list-style: none; padding: 0; margin: 0;"> <li style="margin-bottom: 10px;"> <a href="<?= SITE_URL ?>pages/shop.php" style="color: var(--dark-text); text-decoration: none; display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 8px; transition: var(--transition);" onmouseover="this.style.background='var(--soft-pink)'" onmouseout="this.style.background='transparent'"> <i class="fas fa-th-large" style="color: var(--primary-rose-gold); width: 16px;"></i> All Categories </a> </li> <?php foreach (get_categories() as $cat): ?> <li style="margin-bottom: 10px;"> <a href="<?= SITE_URL ?>pages/shop.php?category=<?= $cat['slug'] ?>" style="color: var(--dark-text); text-decoration: none; display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 8px; transition: var(--transition); <?= $category_slug == $cat['slug'] ? 'background: var(--soft-pink);' : '' ?>" onmouseover="this.style.background='var(--soft-pink)'" onmouseout="this.style.background='<?= $category_slug == $cat['slug'] ? 'var(--soft-pink)' : 'transparent' ?>'"> <i class="<?= $cat['icon'] ?? 'fas fa-tag' ?>" style="color: var(--primary-rose-gold); width: 16px;"></i> <?= htmlspecialchars($cat['name']) ?> </a> </li> <?php endforeach; ?> </ul> </div> <!-- Price Filter --> <div class="filter-widget" style="background: var(--white); padding: 25px; border-radius: 16px; margin-bottom: 20px; box-shadow: var(--shadow-sm);"> <h4 style="font-size: 1.1rem; margin-bottom: 20px; font-family: var(--font-primary); font-weight: 600;">Filter by Price</h4> <form method="GET" action=""> <?php foreach ($_GET as $key => $val): if (!in_array($key, ['min_price', 'max_price', 'page'])): ?> <input type="hidden" name="<?= htmlspecialchars($key) ?>" value="<?= htmlspecialchars($val) ?>"> <?php endif; endforeach; ?> <div class="mb-3"> <label class="form-label small">Price Range</label> <div class="d-flex gap-2 align-items-center"> <input type="number" name="min_price" class="form-control" placeholder="Min" value="<?= $min_price ?>" style="border-radius: 25px; font-size: 0.85rem;"> <span>-</span> <input type="number" name="max_price" class="form-control" placeholder="Max" value="<?= $max_price ?>" style="border-radius: 25px; font-size: 0.85rem;"> </div> </div> <button type="submit" class="btn-luxury w-100" style="border-radius: 25px; padding: 10px;">Apply Filter</button> </form> </div> <!-- Brands --> <div class="filter-widget" style="background: var(--white); padding: 25px; border-radius: 16px; box-shadow: var(--shadow-sm);"> <h4 style="font-size: 1.1rem; margin-bottom: 20px; font-family: var(--font-primary); font-weight: 600;">Brands</h4> <ul class="filter-list" style="list-style: none; padding: 0; margin: 0;"> <?php $brands = $db->query("SELECT * FROM brands WHERE status = 1 ORDER BY name ASC")->fetchAll(); foreach ($brands as $b): ?> <li style="margin-bottom: 8px;"> <a href="<?= SITE_URL ?>pages/shop.php?brand=<?= $b['slug'] ?>" style="color: var(--dark-text); text-decoration: none; display: block; padding: 6px 12px; border-radius: 8px; transition: var(--transition); <?= $brand_slug == $b['slug'] ? 'background: var(--soft-pink);' : '' ?>"> <?= htmlspecialchars($b['name']) ?> </a> </li> <?php endforeach; ?> </ul> </div> </div> </div> <!-- Products Grid --> <div class="col-lg-9 col-md-8"> <!-- Toolbar --> <div class="shop-toolbar" style="background: var(--white); padding: 20px; border-radius: 16px; margin-bottom: 30px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 15px; box-shadow: var(--shadow-sm);"> <div> <p style="margin: 0; color: var(--gray-600);">Showing <strong><?= $offset + 1 ?>-<?= min($offset + $per_page, $total_products) ?></strong> of <strong><?= $total_products ?></strong> products</p> </div> <div> <select class="form-select" onchange="window.location.href=this.value" style="border-radius: 25px; padding: 8px 20px; border: 1px solid var(--gray-300); font-size: 0.9rem;"> <option value="<?= SITE_URL ?>pages/shop.php?<?= http_build_query(array_merge($_GET, ['sort' => 'newest', 'page' => 1])) ?>" <?= $sort == 'newest' ? 'selected' : '' ?>>Sort by: Newest</option> <option value="<?= SITE_URL ?>pages/shop.php?<?= http_build_query(array_merge($_GET, ['sort' => 'price_low', 'page' => 1])) ?>" <?= $sort == 'price_low' ? 'selected' : '' ?>>Price: Low to High</option> <option value="<?= SITE_URL ?>pages/shop.php?<?= http_build_query(array_merge($_GET, ['sort' => 'price_high', 'page' => 1])) ?>" <?= $sort == 'price_high' ? 'selected' : '' ?>>Price: High to Low</option> <option value="<?= SITE_URL ?>pages/shop.php?<?= http_build_query(array_merge($_GET, ['sort' => 'name', 'page' => 1])) ?>" <?= $sort == 'name' ? 'selected' : '' ?>>Name: A to Z</option> <option value="<?= SITE_URL ?>pages/shop.php?<?= http_build_query(array_merge($_GET, ['sort' => 'popular', 'page' => 1])) ?>" <?= $sort == 'popular' ? 'selected' : '' ?>>Most Popular</option> </select> </div> </div> <!-- Products --> <?php if (count($products) > 0): ?> <div class="product-grid"> <?php foreach ($products as $product): ?> <?php include '../includes/product-card.php'; ?> <?php endforeach; ?> </div> <!-- Pagination --> <?php if ($total_pages > 1): ?> <div class="mt-5"> <nav> <ul class="pagination justify-content-center"> <?php if ($page_num > 1): ?> <li class="page-item"> <a class="page-link" href="?<?= http_build_query(array_merge($_GET, ['page' => $page_num - 1])) ?>" style="border-radius: 50%; margin: 0 5px; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--gray-300); color: var(--dark-text);"> <i class="fas fa-chevron-left"></i> </a> </li> <?php endif; ?> <?php for ($i = max(1, $page_num - 2); $i <= min($total_pages, $page_num + 2); $i++): ?> <li class="page-item <?= $i == $page_num ? 'active' : '' ?>"> <a class="page-link" href="?<?= http_build_query(array_merge($_GET, ['page' => $i])) ?>" style="border-radius: 50%; margin: 0 5px; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; <?= $i == $page_num ? 'background: var(--gradient-rose); border-color: var(--primary-rose-gold); color: var(--white);' : 'border: 1px solid var(--gray-300); color: var(--dark-text);' ?>"> <?= $i ?> </a> </li> <?php endfor; ?> <?php if ($page_num < $total_pages): ?> <li class="page-item"> <a class="page-link" href="?<?= http_build_query(array_merge($_GET, ['page' => $page_num + 1])) ?>" style="border-radius: 50%; margin: 0 5px; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--gray-300); color: var(--dark-text);"> <i class="fas fa-chevron-right"></i> </a> </li> <?php endif; ?> </ul> </nav> </div> <?php endif; ?> <?php else: ?> <div class="text-center py-5" style="background: var(--white); border-radius: 16px;"> <i class="fas fa-search" style="font-size: 4rem; color: var(--gray-300); margin-bottom: 20px;"></i> <h3>No products found</h3> <p class="text-muted">Try adjusting your filters or search terms</p> <a href="<?= SITE_URL ?>pages/shop.php" class="btn-luxury mt-3">Browse All Products</a> </div> <?php endif; ?> </div> </div> </div> </section> </main> <?php require_once '../includes/footer.php'; ?>
Save Changes
Cancel
Create New File
Create New Folder