64 lines
2.9 KiB
PHP
64 lines
2.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
require_once __DIR__ . '/includes/bootstrap.php';
|
|
require_once __DIR__ . '/includes/layout.php';
|
|
|
|
$search = isset($_GET['search']) ? trim((string) $_GET['search']) : null;
|
|
$categoryId = isset($_GET['category']) ? (int) $_GET['category'] : null;
|
|
$sort = isset($_GET['sort']) ? (string) $_GET['sort'] : null;
|
|
|
|
$categories = get_categories();
|
|
$products = get_products($search, $categoryId, $sort);
|
|
|
|
render_header('Shop - E-SO9', 'shop');
|
|
?>
|
|
<main class="container my-5">
|
|
<div class="d-flex flex-column flex-lg-row justify-content-between align-items-start align-items-lg-center gap-3 mb-4">
|
|
<div>
|
|
<h1 class="h3 mb-1">Shop all products</h1>
|
|
<p class="text-muted mb-0">Search, filter, and add items to your cart.</p>
|
|
</div>
|
|
<form class="d-flex gap-2" method="get" action="/shop.php">
|
|
<input type="search" name="search" class="form-control" placeholder="Search products" value="<?= e($search ?? '') ?>" />
|
|
<select name="category" class="form-select">
|
|
<option value="">All categories</option>
|
|
<?php foreach ($categories as $category): ?>
|
|
<option value="<?= e((string) $category['id']) ?>" <?= $categoryId === (int) $category['id'] ? 'selected' : '' ?>>
|
|
<?= e($category['name']) ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<select name="sort" class="form-select">
|
|
<option value="">Newest</option>
|
|
<option value="price_asc" <?= $sort === 'price_asc' ? 'selected' : '' ?>>Price low-high</option>
|
|
<option value="price_desc" <?= $sort === 'price_desc' ? 'selected' : '' ?>>Price high-low</option>
|
|
</select>
|
|
<button class="btn btn-outline-secondary" type="submit">Apply</button>
|
|
</form>
|
|
</div>
|
|
|
|
<?php if (!$products): ?>
|
|
<div class="alert alert-light border">No products matched your filters.</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="row g-4">
|
|
<?php foreach ($products as $product): ?>
|
|
<div class="col-md-4">
|
|
<div class="product-card h-100">
|
|
<img src="<?= e($product['image_url'] ?: product_image_data($product['name'])) ?>" class="img-fluid" alt="<?= e($product['name']) ?>" width="600" height="400" />
|
|
<div class="p-3 d-flex flex-column h-100">
|
|
<div class="text-muted small mb-1"><?= e($product['category_name'] ?? 'General') ?></div>
|
|
<h2 class="h6 mb-2"><?= e($product['name']) ?></h2>
|
|
<p class="text-muted small flex-grow-1"><?= e($product['description']) ?></p>
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<span class="fw-semibold"><?= e(format_price((float) $product['price'])) ?></span>
|
|
<a href="/product.php?id=<?= e((string) $product['id']) ?>" class="btn btn-outline-secondary btn-sm">View</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</main>
|
|
<?php render_footer(); ?>
|