37301-vm/product.php
Flatlogic Bot 9bf0056520 test
2026-01-07 09:28:17 +00:00

88 lines
3.3 KiB
PHP

<?php
require_once __DIR__ . '/db/config.php';
$product = null;
$slug = $_GET['slug'] ?? null;
if ($slug) {
try {
$pdo = db();
$stmt = $pdo->prepare('SELECT * FROM products WHERE url_slug = ?');
$stmt->execute([$slug]);
$product = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
error_log('Failed to fetch product: ' . $e->getMessage());
}
}
// If no product is found, send a 404 response
if (!$product) {
http_response_code(404);
require_once __DIR__ . '/includes/header.php';
echo '<div class="container text-center my-5"><h1 class="display-1">404</h1><p class="lead">Product not found.</p><a href="products.php" class="btn btn-primary">Back to Catalog</a></div>';
require_once __DIR__ . '/includes/footer.php';
exit;
}
// --- SEO & Page Variables ---
$seo_title = $product['seo_title'];
$seo_meta_description = $product['seo_meta_description'];
$canonical_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}" . $product['canonical_url'];
$og_title = $product['og_title'];
$og_description = $product['og_description'];
$og_image = $product['og_image']; // Assuming this is a full URL
$og_type = 'product';
$images = json_decode($product['images'], true);
// JSON-LD Schema for Product
$schema = [
'@context' => 'https://schema.org',
'@type' => 'Product',
'name' => $product['name'],
'description' => $product['description'],
'image' => $images, // Array of image URLs
'offers' => [
'@type' => 'Offer',
'priceCurrency' => 'USD', // Change as needed
'price' => '0', // Add a price column if you have one
'availability' => 'https://schema.org/InStock'
]
];
require_once __DIR__ . '/includes/header.php';
?>
<main class="container mt-5">
<div class="row">
<!-- Product Image Gallery -->
<div class="col-md-6 mb-4">
<?php if (!empty($images)): ?>
<img src="<?php echo htmlspecialchars($images[0]); ?>" class="img-fluid rounded shadow-sm mb-3" alt="<?php echo htmlspecialchars($product['name']); ?>">
<div class="row">
<?php foreach (array_slice($images, 1) as $image): ?>
<div class="col-4">
<img src="<?php echo htmlspecialchars($image); ?>" class="img-fluid rounded shadow-sm" alt="<?php echo htmlspecialchars($product['name']); ?> thumbnail">
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<!-- Product Details -->
<div class="col-md-6">
<h1 class="display-5"><?php echo htmlspecialchars($product['name']); ?></h1>
<p class="lead text-muted"><?php echo htmlspecialchars($product['material']); ?></p>
<hr>
<p><?php echo nl2br(htmlspecialchars($product['description'])); ?></p>
<h5 class="mt-4">Application</h5>
<p><?php echo htmlspecialchars($product['application']); ?></p>
<div class="mt-4">
<a href="/contact.php" class="btn btn-primary btn-lg">Inquire Now</a>
</div>
</div>
</div>
</main>
<?php require_once __DIR__ . '/includes/footer.php'; ?>