65 lines
2.7 KiB
PHP
65 lines
2.7 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../app/Controllers/ProductController.php';
|
|
|
|
$slug = $_GET['slug'] ?? null;
|
|
|
|
if (!$slug) {
|
|
header("Location: index.php");
|
|
exit();
|
|
}
|
|
|
|
$pc = new ProductController();
|
|
$product = $pc->show($slug);
|
|
|
|
require_once __DIR__ . '/../app/Views/public/header.php';
|
|
?>
|
|
|
|
<main class="container my-5">
|
|
<div class="page-header-product">
|
|
<!-- Breadcrumb could go here -->
|
|
</div>
|
|
<?php if ($product): ?>
|
|
<section class="row">
|
|
<div class="col-md-6">
|
|
<?php
|
|
$image_path = !empty($product['image'])
|
|
? 'uploads/products/' . htmlspecialchars($product['image'])
|
|
: 'https://picsum.photos/800/600?random=' . $product['id'];
|
|
?>
|
|
<img src="<?= $image_path ?>" class="img-fluid rounded product-image-single" alt="<?= htmlspecialchars($product['name']) ?>">
|
|
</div>
|
|
<div class="col-md-6">
|
|
<h1 class="display-5"><?= htmlspecialchars($product['name']) ?></h1>
|
|
<p class="text-muted">Categoria: <?= htmlspecialchars($product['category_name']) ?></p>
|
|
<p class="card-price display-6 mb-3">R$ <?= number_format($product['price'], 2, ',', '.') ?></p>
|
|
<p class="lead"><?= nl2br(htmlspecialchars($product['description'])) ?></p>
|
|
|
|
<form action="/app/Controllers/CartController.php" method="POST">
|
|
<input type="hidden" name="action" value="add">
|
|
<input type="hidden" name="product_id" value="<?= $product['id'] ?>">
|
|
<input type="hidden" name="product_slug" value="<?= $product['slug'] ?>">
|
|
<div class="row">
|
|
<div class="col-md-4">
|
|
<label for="quantity" class="form-label">Quantidade</label>
|
|
<input type="number" name="quantity" id="quantity" class="form-control" value="1" min="1">
|
|
</div>
|
|
</div>
|
|
<div class="d-grid gap-2 d-md-block mt-4">
|
|
<button class="btn btn-primary btn-lg" type="submit">Adicionar ao Carrinho</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</section>
|
|
<?php else: ?>
|
|
<div class="alert alert-danger text-center" role="alert">
|
|
<h4 class="alert-heading">Oops!</h4>
|
|
<p>O produto que você está procurando não foi encontrado.</p>
|
|
<hr>
|
|
<a href="catalog.php" class="btn btn-secondary">Voltar ao Catálogo</a>
|
|
</div>
|
|
<?php endif; ?>
|
|
</main>
|
|
|
|
<?php
|
|
require_once __DIR__ . '/../app/Views/public/footer.php';
|
|
?>
|