104 lines
4.1 KiB
PHP
104 lines
4.1 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
$product = null;
|
|
$error_message = null;
|
|
$slug = $_GET['slug'] ?? null;
|
|
|
|
if (!$slug) {
|
|
header("Location: products.php");
|
|
exit();
|
|
}
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare('SELECT * FROM products WHERE slug = :slug');
|
|
$stmt->bindParam(':slug', $slug, PDO::PARAM_STR);
|
|
$stmt->execute();
|
|
$product = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$product) {
|
|
http_response_code(404);
|
|
$error_message = "Product not found.";
|
|
}
|
|
|
|
} catch (PDOException $e) {
|
|
$error_message = "Database error: " . $e->getMessage();
|
|
}
|
|
|
|
function format_price($price) {
|
|
return 'đ' . number_format($price, 0, ',', '.');
|
|
}
|
|
|
|
$page_title = $product ? $product['name'] : 'Product Not Found';
|
|
$meta_description = $product ? htmlspecialchars($product['description']) : 'The requested product could not be found.';
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?php echo htmlspecialchars($page_title); ?> - bconcept</title>
|
|
<meta name="description" content="<?php echo $meta_description; ?>">
|
|
<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;600&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">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">
|
|
<div class="container">
|
|
<?php if ($error_message): ?>
|
|
<div class="notice notice-error" style="margin-top: 2rem;"><?php echo $error_message; ?></div>
|
|
<?php elseif ($product): ?>
|
|
<div class="product-detail-layout">
|
|
<div class="product-detail-images">
|
|
<img src="<?php echo htmlspecialchars($product['image_url']); ?>" alt="<?php echo htmlspecialchars($product['name']); ?>" class="main-product-image">
|
|
</div>
|
|
<div class="product-detail-info">
|
|
<h1 class="product-title"><?php echo htmlspecialchars($product['name']); ?></h1>
|
|
<p class="product-price-detail"><?php echo format_price($product['price']); ?></p>
|
|
<div class="product-description">
|
|
<?php echo nl2br(htmlspecialchars($product['description'])); ?>
|
|
</div>
|
|
<form class="add-to-cart-form">
|
|
<div class="quantity-selector">
|
|
<label for="quantity">Quantity:</label>
|
|
<input type="number" id="quantity" name="quantity" value="1" min="1" class="quantity-input">
|
|
</div>
|
|
<button type="submit" class="btn-primary">Add to Cart</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</main>
|
|
|
|
<footer class="site-footer">
|
|
<div class="container">
|
|
<p>© <?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>
|