35067-vm/products.php
Flatlogic Bot b200618254 eco-grow
2025-10-20 06:45:18 +00:00

108 lines
5.0 KiB
PHP

<?php
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
require_once 'db/config.php';
// Fetch all products with their vendor names
$products = [];
try {
$sql = "SELECT p.id, p.name, p.description, p.price, p.image_url, u.name AS vendor_name
FROM products p
JOIN users u ON p.vendor_id = u.id
ORDER BY p.created_at DESC";
$stmt = db()->prepare($sql);
$stmt->execute();
$products = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
// Handle database errors gracefully
error_log("Database error: " . $e->getMessage());
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>All Products - EcoGrow</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&family=Roboto:wght@400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<?php include 'includes/header.php'; ?>
<header class="bg-success text-white text-center py-5">
<div class="container">
<h1 class="display-4 fw-bold">Our Products</h1>
<p class="lead">Browse our collection of eco-friendly and sustainable products from various vendors.</p>
</div>
</header>
<main class="container my-5">
<section id="all-products">
<div class="row">
<?php if (empty($products)): ?>
<div class="col">
<p class="text-center">No products have been added yet. Please check back later!</p>
</div>
<?php else: ?>
<?php foreach ($products as $product): ?>
<div class="col-lg-3 col-md-4 col-sm-6 mb-4">
<div class="card product-card h-100">
<img src="<?php echo htmlspecialchars($product['image_url']); ?>" class="card-img-top product-card-img" alt="<?php echo htmlspecialchars($product['name']); ?>">
<div class="card-body d-flex flex-column">
<h5 class="card-title"><?php echo htmlspecialchars($product['name']); ?></h5>
<p class="card-text text-muted mb-2">By <?php echo htmlspecialchars($product['vendor_name']); ?></p>
<p class="card-text text-success fw-bold fs-5 mt-auto">$<?php echo htmlspecialchars($product['price']); ?></p>
<div class="d-grid gap-2">
<form action="add_to_cart.php" method="post">
<input type="hidden" name="product_id" value="<?php echo htmlspecialchars($product['id']); ?>">
<button type="submit" class="btn btn-primary w-100">Add to Cart</button>
</form>
<a href="checkout.php?product_id=<?php echo htmlspecialchars($product['id']); ?>" class="btn btn-success w-100">Buy Now</a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</section>
</main>
<footer class="bg-dark text-white pt-5 pb-3">
<div class="container text-center">
<div class="row">
<div class="col-md-4 mb-4">
<h5 class="text-uppercase">EcoGrow</h5>
<p>Your partner in sustainable living. We provide the tools and tips to help you grow a greener future.</p>
</div>
<div class="col-md-4 mb-4">
<h5 class="text-uppercase">Quick Links</h5>
<ul class="list-unstyled">
<li><a href="index.php#hero" class="text-white">Home</a></li>
<li><a href="products.php" class="text-white">Shop</a></li>
<li><a href="index.php#blog" class="text-white">Blog</a></li>
<li><a href="#" class="text-white">Contact</a></li>
</ul>
</div>
<div class="col-md-4 mb-4">
<h5 class="text-uppercase">Follow Us</h5>
<a href="#" class="text-white me-3"><i class="fab fa-facebook-f"></i></a>
<a href="#" class="text-white me-3"><i class="fab fa-twitter"></i></a>
<a href="#" class="text-white me-3"><i class="fab fa-instagram"></i></a>
</div>
</div>
<hr>
<p class="mb-0">&copy; <?php echo date("Y"); ?> EcoGrow. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>