97 lines
5.0 KiB
PHP
97 lines
5.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
session_start();
|
|
require_once __DIR__ . '/includes/store.php';
|
|
|
|
$notice = '';
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'add') {
|
|
$id = (string)($_POST['product_id'] ?? '');
|
|
$qty = max(1, min(20, (int)($_POST['qty'] ?? 1)));
|
|
$product = get_product($id);
|
|
if ($product) {
|
|
$_SESSION['cart'][$id] = min((int)$product['stock'], (int)($_SESSION['cart'][$id] ?? 0) + $qty);
|
|
$next = (string)($_POST['next'] ?? 'cart');
|
|
if ($next === 'checkout') {
|
|
header('Location: checkout.php');
|
|
exit;
|
|
}
|
|
header('Location: cart.php?added=' . rawurlencode($id));
|
|
exit;
|
|
}
|
|
$notice = 'No pudimos agregar el producto. Inténtalo de nuevo.';
|
|
}
|
|
|
|
layout_header('Tienda virtual', 'LA BORGUITA: tienda virtual con catálogo, carrito, QR de pago y confirmación manual.');
|
|
$products = store_products();
|
|
$logoPath = store_logo_path();
|
|
?>
|
|
<section class="hero py-5">
|
|
<div class="container">
|
|
<?php if ($notice): ?><div class="alert alert-success alert-dismissible fade show" role="alert"><?= h($notice) ?><button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Cerrar"></button></div><?php endif; ?>
|
|
<div class="row align-items-center g-4">
|
|
<div class="col-lg-7">
|
|
<span class="eyebrow">Super market 24 · USD · Pago manual</span>
|
|
<h1 class="display-5 fw-bold mt-3 mb-3">LA BORGUITA vende rápido, confirma pagos y atiende por WhatsApp.</h1>
|
|
<p class="lead text-secondary mb-4">Un MVP de tienda virtual con productos activos, stock visible, carrito, QR de pago reservado y comprobantes para aprobación del admin.</p>
|
|
<div class="d-flex flex-wrap gap-2">
|
|
<a class="btn btn-dark btn-lg" href="#catalogo">Comprar ahora</a>
|
|
<a class="btn btn-outline-dark btn-lg" href="cart.php">Ver carrito</a>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-5">
|
|
<div class="market-card">
|
|
<div class="market-top"><span class="brand-logo lg"><img src="<?= h($logoPath) ?>" alt="" width="64" height="64"></span><div><strong>LA BORGUITA</strong><small>Pagos Visa · Mastercard · Transferencia</small><?= payment_icons_html('compact') ?></div></div>
|
|
<div class="scan-box"><span>Espacio para QR de pago</span><small>Sube aquí tu QR definitivo desde el editor cuando lo tengas listo.</small></div>
|
|
<div class="status-row"><span>Pedidos pendientes</span><strong>Revisión manual</strong></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="py-5 border-top" id="catalogo">
|
|
<div class="container">
|
|
<div class="section-heading">
|
|
<span class="eyebrow">Catálogo activo</span>
|
|
<h2>Productos iniciales</h2>
|
|
<p>Luego el panel admin puede ampliarse para crear nuevos productos, editar precios y controlar almacén.</p>
|
|
</div>
|
|
<div class="row g-3">
|
|
<?php foreach ($products as $product): ?>
|
|
<div class="col-md-6 col-lg-4">
|
|
<article class="product-card h-100">
|
|
<div class="product-visual" aria-hidden="true"><span><?= h(substr($product['name'], 0, 2)) ?></span></div>
|
|
<div class="product-body">
|
|
<div class="d-flex justify-content-between gap-2"><span class="badge subtle"><?= h($product['category']) ?></span><span class="stock">Stock <?= (int)$product['stock'] ?></span></div>
|
|
<h3><?= h($product['name']) ?></h3>
|
|
<p><?= h($product['description']) ?></p>
|
|
<div class="price"><?= h(money((float)$product['price'])) ?></div>
|
|
<form method="post" class="product-actions mt-3">
|
|
<input type="hidden" name="action" value="add">
|
|
<input type="hidden" name="product_id" value="<?= h($product['id']) ?>">
|
|
<div class="d-flex gap-2 align-items-center flex-wrap">
|
|
<input class="form-control qty" type="number" name="qty" value="1" min="1" max="<?= (int)$product['stock'] ?>" aria-label="Cantidad">
|
|
<button class="btn btn-dark" type="submit" name="next" value="cart">Agregar</button>
|
|
<button class="btn btn-outline-dark" type="submit" name="next" value="checkout">Pagar</button>
|
|
<a class="btn btn-outline-secondary" href="product.php?id=<?= h($product['id']) ?>">Detalle</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</article>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="py-5">
|
|
<div class="container">
|
|
<div class="row g-3">
|
|
<div class="col-md-4"><div class="feature"><strong>QR reservado</strong><span>Bloque visual listo para colocar el código real.</span></div></div>
|
|
<div class="col-md-4"><div class="feature"><strong>Visa/Mastercard</strong><span>Método visible para integrar pasarelas MX/US.</span><?= payment_icons_html('mt-2') ?></div></div>
|
|
<div class="col-md-4"><div class="feature"><strong>Admin aprueba</strong><span>Los comprobantes quedan pendientes hasta revisión.</span></div></div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
<?php layout_footer(); ?>
|