35410-vm/products.php
2025-11-02 05:34:28 +00:00

100 lines
4.2 KiB
PHP

<?php
require_once 'db/config.php';
$products = [];
$error_message = null;
try {
$pdo = db();
$stmt = $pdo->query('SELECT id, name, price, image_url, slug FROM products ORDER BY created_at DESC');
if ($stmt) {
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
} catch (PDOException $e) {
// If the table doesn't exist, it's not a fatal error for the page load.
if ($e->getCode() === '42S02') {
$error_message = "The products table is not available. Please run the installer.";
} else {
$error_message = "An error occurred: " . $e->getMessage();
}
}
function format_price($price) {
return 'đ' . number_format($price, 0, ',', '.');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>All Products - bconcept</title>
<meta name="description" content="Browse our full collection of high-quality men's formal wear and footwear.">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@700&family=Inter:wght@400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<div class="site-container">
<header class="site-header">
<div class="container">
<div class="header-content">
<a href="index.php" class="logo">bconcept</a>
<nav class="main-nav">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="products.php" class="active">All Products</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</div>
</div>
</header>
<main class="site-content">
<section class="hero-small">
<div class="container">
<h1>All Products</h1>
<p>Discover our curated collection of timeless pieces.</p>
</div>
</section>
<section class="product-grid-section">
<div class="container">
<?php if ($error_message): ?>
<div class="notice notice-error"><?php echo htmlspecialchars($error_message); ?></div>
<?php elseif (empty($products)): ?>
<div class="notice">No products are currently available.</div>
<?php else: ?>
<div class="product-grid">
<?php foreach ($products as $product): ?>
<div class="product-card">
<a href="product-detail.php?slug=<?php echo htmlspecialchars($product['slug']); ?>" class="product-card-link">
<div class="product-image-wrapper">
<img src="<?php echo htmlspecialchars($product['image_url']); ?>" alt="<?php echo htmlspecialchars($product['name']); ?>" class="product-image">
</div>
<div class="product-info">
<h3 class="product-name"><?php echo htmlspecialchars($product['name']); ?></h3>
<p class="product-price"><?php echo format_price($product['price']); ?></p>
</div>
</a>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</section>
</main>
<footer class="site-footer">
<div class="container">
<p>&copy; <?php echo date('Y'); ?> bconcept. All Rights Reserved.</p>
</div>
</footer>
</div>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>