'; require_once __DIR__ . '/includes/functions.php'; // Get filters $category = $_GET['category'] ?? ''; $subcat = $_GET['subcat'] ?? ''; $search = $_GET['search'] ?? ''; $sort = $_GET['sort'] ?? 'newest'; $page = max(1, intval($_GET['page'] ?? 1)); // Build query $where = ['is_active = 1']; $params = []; if ($category) { $where[] = 'category = :category'; $params['category'] = $category; } if ($subcat) { $where[] = 'product_type_id = :subcat'; $params['subcat'] = $subcat; } if ($search) { $where[] = '(name LIKE :search OR description LIKE :search)'; $params['search'] = '%' . $search . '%'; } $whereClause = implode(' AND ', $where); // Prefix columns that are ambiguous in the JOIN query $joinWhereClause = str_replace( ['is_active = 1', 'category =', 'product_type_id =', '(name LIKE', 'description LIKE'], ['p.is_active = 1', 'p.category =', 'p.product_type_id =', '(p.name LIKE', 'p.description LIKE'], $whereClause ); // Sort $orderBy = match($sort) { 'price_low' => 'COALESCE(p.sale_price, p.price) ASC', 'price_high' => 'COALESCE(p.sale_price, p.price) DESC', 'name' => 'p.name ASC', default => 'p.created_at DESC' }; // Get total count $totalProducts = db()->count('products', $whereClause, $params); $pagination = paginate($totalProducts, $page, 12); // Get products $products = db()->fetchAll( "SELECT p.*, pt.name AS type_name, pt.type_id AS type_slug FROM products p LEFT JOIN product_types pt ON p.product_type_id = pt.type_id WHERE {$joinWhereClause} ORDER BY {$orderBy} LIMIT :limit OFFSET :offset", array_merge($params, ['limit' => $pagination['per_page'], 'offset' => $pagination['offset']]) ); // Get categories for filter $categories = db()->fetchAll( "SELECT DISTINCT category FROM products WHERE category IS NOT NULL AND category != '' AND is_active = 1 ORDER BY category" ); $metaTitle = "Shop Premium Coffee Beans | Tom's Java Jive"; $metaDescription = 'Browse our selection of premium artisan coffee beans. Single origin, blends, light, medium and dark roasts. Free shipping over $50.'; $metaKeywords = 'buy coffee beans online, artisan coffee, single origin, blends, light roast, dark roast'; $canonicalUrl = 'https://tomsjavajive.com/shop.php'; require_once __DIR__ . '/includes/header.php'; $productTypesList = db()->fetchAll("SELECT type_id, name, slug FROM product_types WHERE is_active=1 ORDER BY sort_order ASC"); ?> $category, 'subcat' => $subcat])); $filterQs = $filterQs ? '&' . $filterQs : ''; ?>

Our Coffee Collection

Category: All Type: All

Showing of products

No products found

Try adjusting your search or filters

View All Products
<?= htmlspecialchars($product['name']) ?> Sale Featured

1): ?> $category, 'sort' => $sort]))) ?>