catalogo y carrito de compras
This commit is contained in:
+181
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
include("db.php");
|
||||
|
||||
$total = 0;
|
||||
$productos_en_carrito = [];
|
||||
|
||||
if (!empty($_SESSION['carrito'])) {
|
||||
$ids = array_keys($_SESSION['carrito']);
|
||||
$lista_ids = implode(',', $ids);
|
||||
|
||||
$query = "SELECT * FROM productos WHERE id IN ($lista_ids)";
|
||||
$resultado = $conexion->query($query);
|
||||
|
||||
if ($resultado) {
|
||||
while ($row = $resultado->fetch_assoc()) {
|
||||
$row['cantidad'] = $_SESSION['carrito'][$row['id']];
|
||||
$row['subtotal'] = $row['precio'] * $row['cantidad'];
|
||||
$total += $row['subtotal'];
|
||||
$productos_en_carrito[] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
//$estado_local = 'abierto'; // PARA PRUEBAS SOLAMENTE !!!!
|
||||
$estado_local = es_horario_comercial($conexion);
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Tu carrito - La Pecosa</title>
|
||||
<link rel="stylesheet" href="css/all.min.css">
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body { font-family: 'Segoe UI', sans-serif; background-color: #fffef8; color: #333; }
|
||||
.container { max-width: 900px; margin: 50px auto; padding: 20px; background: white; border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.05); }
|
||||
|
||||
h1 { color: #e02828; margin-bottom: 30px; border-bottom: 2px solid #fdf0f0; padding-bottom: 10px; }
|
||||
|
||||
table { width: 100%; border-collapse: collapse; margin-bottom: 30px; }
|
||||
th { text-align: left; padding: 15px; border-bottom: 2px solid #eee; color: #666; text-transform: uppercase; font-size: 0.8rem; }
|
||||
td { padding: 15px; border-bottom: 1px solid #eee; vertical-align: middle; }
|
||||
|
||||
.img-thumb { width: 60px; height: 60px; object-fit: cover; border-radius: 8px; }
|
||||
.cantidad-controles { display: flex; align-items: center; gap: 10px; }
|
||||
.btn-accion { text-decoration: none; color: #e02828; font-size: 1.2rem; transition: 0.2s; display: inline-block; }
|
||||
.btn-accion:hover { color: #333; }
|
||||
|
||||
.btn-accion.deshabilitado {
|
||||
color: #ccc !important;
|
||||
cursor: not-allowed !important;
|
||||
opacity: 0.5;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.total-container { text-align: right; padding: 20px; background: #fdf0f0; border-radius: 10px; }
|
||||
.total-container h2 { color: #e02828; font-size: 2rem; }
|
||||
|
||||
.botones-final { display: flex; justify-content: space-between; align-items: center; margin-top: 30px; }
|
||||
.btn { padding: 15px 30px; border-radius: 50px; text-decoration: none; font-weight: 600; transition: 0.3s; }
|
||||
.btn-volver { background: #eee; color: #666; }
|
||||
.btn-pagar { background: #e02828; color: white; box-shadow: 0 4px 15px rgba(224, 40, 40, 0.3); border: none; cursor: pointer; font-size: 1rem; }
|
||||
.btn-pagar:hover { transform: scale(1.05); background: #c02020; }
|
||||
|
||||
.vacio { text-align: center; padding: 50px; color: #999; }
|
||||
|
||||
.alerta-horario {
|
||||
background: #fee2e2;
|
||||
color: #991b1b;
|
||||
padding: 18px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid #fca5a5;
|
||||
margin-top: 25px;
|
||||
font-size: 0.95rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.alerta-horario h4 {
|
||||
font-size: 1.1rem;
|
||||
margin-bottom: 5px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<h1><i class="fa-solid fa-basket-shopping"></i> Mi carrito</h1>
|
||||
|
||||
<?php if (empty($productos_en_carrito)): ?>
|
||||
<div class="vacio">
|
||||
<p>Tu carrito está vacío.</p>
|
||||
<br>
|
||||
<a href="productos.php" class="btn btn-pagar">Ir a comprar algo rico</a>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Producto</th>
|
||||
<th>Precio</th>
|
||||
<th>Cantidad</th>
|
||||
<th>Subtotal</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($productos_en_carrito as $p):
|
||||
$stock_disponible = isset($p['stock']) ? (int)$p['stock'] : 0;
|
||||
$limite_alcanzado = ($p['cantidad'] >= $stock_disponible);
|
||||
?>
|
||||
<tr>
|
||||
<td style="display: flex; align-items: center; gap: 15px;">
|
||||
<img src="<?php echo $p['imagen']; ?>" class="img-thumb">
|
||||
<strong><?php echo htmlspecialchars($p['nombre']); ?></strong>
|
||||
</td>
|
||||
<td>$<?php echo number_format($p['precio'], 0, ',', '.'); ?></td>
|
||||
<td>
|
||||
<div class="cantidad-controles">
|
||||
<a href="gestionar_carrito.php?accion=quitar&id=<?php echo $p['id']; ?>" class="btn-accion">
|
||||
<i class="fa-solid fa-circle-minus"></i>
|
||||
</a>
|
||||
|
||||
<span><?php echo $p['cantidad']; ?></span>
|
||||
|
||||
<?php if ($limite_alcanzado): ?>
|
||||
<span class="btn-accion deshabilitado" title="Alcanzaste el máximo de stock disponible (<?php echo $stock_disponible; ?>)">
|
||||
<i class="fa-solid fa-circle-plus"></i>
|
||||
</span>
|
||||
<?php else: ?>
|
||||
<a href="gestionar_carrito.php?accion=agregar&id=<?php echo $p['id']; ?>&origen=carrito" class="btn-accion">
|
||||
<i class="fa-solid fa-circle-plus"></i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</td>
|
||||
<td>$<?php echo number_format($p['subtotal'], 0, ',', '.'); ?></td>
|
||||
<td>
|
||||
<a href="gestionar_carrito.php?accion=eliminar&id=<?php echo $p['id']; ?>" style="color: #ccc;"><i class="fa-solid fa-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="total-container">
|
||||
<p>Total a pagar:</p>
|
||||
<h2>$<?php echo number_format($total, 0, ',', '.'); ?></h2>
|
||||
</div>
|
||||
|
||||
<?php if ($estado_local !== 'abierto'): ?>
|
||||
<div class="alerta-horario">
|
||||
<h4><i class="fa-solid fa-store-slash"></i> Local cerrado temporalmente</h4>
|
||||
<?php
|
||||
if ($estado_local === 'manual_cerrado') {
|
||||
echo "El establecimiento se encuentra cerrado por razones de fuerza mayor o mantenimiento edilicio. Disculpe las molestias.";
|
||||
} else {
|
||||
echo "Actualmente nos encontramos fuera del horario de atención al público.<br>";
|
||||
echo "<strong>Horarios de entrega:</strong> Lunes a Sábados de 08:30 a 13:30 y de 17:30 a 21:00 hs. · Domingos de 09:00 a 13:00 hs.";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="botones-final">
|
||||
<a href="productos.php" class="btn btn-volver">← Seguir comprando</a>
|
||||
|
||||
<?php if ($estado_local === 'abierto'): ?>
|
||||
<a href="formulario_entrega.php" class="btn btn-pagar">Finalizar pedido</a>
|
||||
<?php else: ?>
|
||||
<button class="btn" style="background: #cbd5e1; color: #94a3b8; cursor: not-allowed; border: none; font-weight: 600; padding: 15px 30px; border-radius: 50px;" disabled title="El comercio se encuentra cerrado">
|
||||
Finalizar pedido
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user