Auto commit: 2026-06-30T16:12:24.678Z
This commit is contained in:
parent
d3af684449
commit
7a69e52c1e
36
admin.php
Normal file
36
admin.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
session_start();
|
||||
require_once __DIR__ . '/includes/store.php';
|
||||
$message = '';
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'approve') {
|
||||
approve_order((int)($_POST['order_id'] ?? 0));
|
||||
$message = 'Pago aprobado correctamente.';
|
||||
}
|
||||
$orders = list_orders();
|
||||
layout_header('Panel admin', 'Panel admin para revisar comprobantes y aprobar pagos de LA BORGUITA.');
|
||||
?>
|
||||
<section class="py-5">
|
||||
<div class="container">
|
||||
<?php if ($message): ?><div class="alert alert-success alert-dismissible fade show" role="alert"><?= h($message) ?><button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Cerrar"></button></div><?php endif; ?>
|
||||
<div class="section-heading"><span class="eyebrow">Admin</span><h1>Pagos y pedidos</h1><p>Primera versión del panel: revisión de comprobantes, estado del pago y total vendido.</p></div>
|
||||
<?php if (!$orders): ?>
|
||||
<div class="empty-state"><h2>Sin pedidos todavía</h2><p>Cuando un cliente suba comprobante aparecerá aquí para aprobarlo.</p><a class="btn btn-dark" href="index.php#catalogo">Crear pedido de prueba</a></div>
|
||||
<?php else: ?>
|
||||
<div class="accordion orders" id="orders">
|
||||
<?php foreach ($orders as $order): $items = json_decode((string)$order['items_json'], true) ?: []; ?>
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header"><button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#order<?= (int)$order['id'] ?>">#<?= (int)$order['id'] ?> · <?= h($order['customer_name']) ?> · <?= h(money((float)$order['total'])) ?> <span class="status <?= h($order['status']) ?> ms-2"><?= h($order['status']) ?></span></button></h2>
|
||||
<div id="order<?= (int)$order['id'] ?>" class="accordion-collapse collapse" data-bs-parent="#orders"><div class="accordion-body">
|
||||
<div class="row g-3"><div class="col-md-6"><strong>Cliente</strong><p><?= h($order['customer_email']) ?><br><?= h($order['customer_phone']) ?></p></div><div class="col-md-6"><strong>Método</strong><p><?= h($order['payment_method']) ?> · <?= h($order['created_at']) ?></p></div></div>
|
||||
<div class="table-responsive"><table class="table table-sm"><thead><tr><th>Producto</th><th>Cant.</th><th>Subtotal</th></tr></thead><tbody><?php foreach ($items as $item): ?><tr><td><?= h($item['name'] ?? '') ?></td><td><?= (int)($item['qty'] ?? 0) ?></td><td><?= h(money((float)($item['line_total'] ?? 0))) ?></td></tr><?php endforeach; ?></tbody></table></div>
|
||||
<?php if (!empty($order['proof_path'])): ?><a class="btn btn-outline-dark btn-sm" href="<?= h($order['proof_path']) ?>" target="_blank" rel="noopener">Ver comprobante</a><?php endif; ?>
|
||||
<?php if ($order['status'] !== 'approved'): ?><form method="post" class="d-inline"><input type="hidden" name="action" value="approve"><input type="hidden" name="order_id" value="<?= (int)$order['id'] ?>"><button class="btn btn-dark btn-sm" type="submit">Aprobar pago</button></form><?php endif; ?>
|
||||
</div></div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php layout_footer(); ?>
|
||||
File diff suppressed because one or more lines are too long
@ -1,39 +1 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const chatForm = document.getElementById('chat-form');
|
||||
const chatInput = document.getElementById('chat-input');
|
||||
const chatMessages = document.getElementById('chat-messages');
|
||||
|
||||
const appendMessage = (text, sender) => {
|
||||
const msgDiv = document.createElement('div');
|
||||
msgDiv.classList.add('message', sender);
|
||||
msgDiv.textContent = text;
|
||||
chatMessages.appendChild(msgDiv);
|
||||
chatMessages.scrollTop = chatMessages.scrollHeight;
|
||||
};
|
||||
|
||||
chatForm.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const message = chatInput.value.trim();
|
||||
if (!message) return;
|
||||
|
||||
appendMessage(message, 'visitor');
|
||||
chatInput.value = '';
|
||||
|
||||
try {
|
||||
const response = await fetch('api/chat.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ message })
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
// Artificial delay for realism
|
||||
setTimeout(() => {
|
||||
appendMessage(data.reply, 'bot');
|
||||
}, 500);
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
appendMessage("Sorry, something went wrong. Please try again.", 'bot');
|
||||
}
|
||||
});
|
||||
});
|
||||
window.addEventListener('load',()=>{setTimeout(()=>{document.getElementById('loader')?.classList.add('is-hidden')},350)});document.querySelectorAll('input[type="number"]').forEach(input=>{input.addEventListener('change',()=>{const min=Number(input.min||0);const max=Number(input.max||999);let value=Number(input.value||min);if(value<min)value=min;if(value>max)value=max;input.value=String(value)})});
|
||||
|
||||
37
cart.php
Normal file
37
cart.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
session_start();
|
||||
require_once __DIR__ . '/includes/store.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (($_POST['action'] ?? '') === 'clear') { $_SESSION['cart'] = []; }
|
||||
if (($_POST['action'] ?? '') === 'update') {
|
||||
foreach (($_POST['qty'] ?? []) as $id => $qty) {
|
||||
$product = get_product((string)$id);
|
||||
if ($product) {
|
||||
$qty = max(0, min((int)$product['stock'], (int)$qty));
|
||||
if ($qty === 0) { unset($_SESSION['cart'][$id]); } else { $_SESSION['cart'][$id] = $qty; }
|
||||
}
|
||||
}
|
||||
}
|
||||
header('Location: cart.php'); exit;
|
||||
}
|
||||
$items = cart_items();
|
||||
layout_header('Carrito', 'Carrito de compra LA BORGUITA con precios en dólares.');
|
||||
?>
|
||||
<section class="py-5">
|
||||
<div class="container">
|
||||
<div class="section-heading"><span class="eyebrow">Carrito</span><h1>Revisa tu compra</h1><p>Ajusta cantidades antes de subir el comprobante de pago.</p></div>
|
||||
<?php if (!$items): ?>
|
||||
<div class="empty-state"><h2>Tu carrito está vacío</h2><p>Agrega productos del catálogo para iniciar un pedido.</p><a class="btn btn-dark" href="index.php#catalogo">Ir al catálogo</a></div>
|
||||
<?php else: ?>
|
||||
<form method="post">
|
||||
<input type="hidden" name="action" value="update">
|
||||
<div class="table-responsive surface"><table class="table align-middle mb-0"><thead><tr><th>Producto</th><th>Precio</th><th>Cantidad</th><th>Total</th></tr></thead><tbody>
|
||||
<?php foreach ($items as $item): ?><tr><td><strong><?= h($item['name']) ?></strong><br><small class="text-secondary">Stock <?= (int)$item['stock'] ?></small></td><td><?= h(money((float)$item['price'])) ?></td><td><input class="form-control qty" type="number" name="qty[<?= h($item['id']) ?>]" value="<?= (int)$item['qty'] ?>" min="0" max="<?= (int)$item['stock'] ?>"></td><td><?= h(money((float)$item['line_total'])) ?></td></tr><?php endforeach; ?>
|
||||
</tbody></table></div>
|
||||
<div class="cart-actions"><button class="btn btn-outline-dark" type="submit">Actualizar</button><button class="btn btn-outline-secondary" type="submit" name="action" value="clear">Vaciar</button><div class="ms-md-auto total">Total: <?= h(money(cart_total())) ?></div><a class="btn btn-dark btn-lg" href="checkout.php">Continuar al pago</a></div>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php layout_footer(); ?>
|
||||
91
checkout.php
Normal file
91
checkout.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
session_start();
|
||||
require_once __DIR__ . '/includes/store.php';
|
||||
$items = cart_items();
|
||||
$errors = [];
|
||||
$orderId = null;
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (!$items) { $errors[] = 'Tu carrito está vacío.'; }
|
||||
$name = trim((string)($_POST['customer_name'] ?? ''));
|
||||
$email = trim((string)($_POST['customer_email'] ?? ''));
|
||||
$phone = trim((string)($_POST['customer_phone'] ?? ''));
|
||||
$notes = trim((string)($_POST['delivery_notes'] ?? ''));
|
||||
$method = (string)($_POST['payment_method'] ?? 'qr');
|
||||
if ($name === '' || mb_strlen($name) < 2) { $errors[] = 'Escribe tu nombre.'; }
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors[] = 'Escribe un email válido.'; }
|
||||
if ($phone === '' || mb_strlen($phone) < 6) { $errors[] = 'Escribe un teléfono válido.'; }
|
||||
if (!in_array($method, ['qr', 'card', 'transfer'], true)) { $errors[] = 'Selecciona un método de pago.'; }
|
||||
|
||||
$proofPath = null;
|
||||
if (isset($_FILES['proof']) && is_uploaded_file($_FILES['proof']['tmp_name'])) {
|
||||
$max = 8 * 1024 * 1024;
|
||||
$allowed = ['image/jpeg' => 'jpg', 'image/png' => 'png', 'application/pdf' => 'pdf'];
|
||||
$mime = mime_content_type($_FILES['proof']['tmp_name']) ?: '';
|
||||
if ($_FILES['proof']['size'] > $max) { $errors[] = 'El comprobante no puede superar 8 MB.'; }
|
||||
if (!isset($allowed[$mime])) { $errors[] = 'El comprobante debe ser JPG, PNG o PDF.'; }
|
||||
if (!$errors) {
|
||||
$dir = __DIR__ . '/assets/uploads';
|
||||
if (!is_dir($dir)) { mkdir($dir, 0775, true); }
|
||||
$filename = 'proof-' . date('YmdHis') . '-' . bin2hex(random_bytes(4)) . '.' . $allowed[$mime];
|
||||
if (move_uploaded_file($_FILES['proof']['tmp_name'], $dir . '/' . $filename)) {
|
||||
$proofPath = 'assets/uploads/' . $filename;
|
||||
} else { $errors[] = 'No se pudo guardar el comprobante.'; }
|
||||
}
|
||||
} else {
|
||||
$errors[] = 'Sube el comprobante para revisión manual.';
|
||||
}
|
||||
|
||||
if (!$errors) {
|
||||
$orderId = create_order([
|
||||
'customer_name' => $name,
|
||||
'customer_email' => $email,
|
||||
'customer_phone' => $phone,
|
||||
'delivery_notes' => $notes,
|
||||
'payment_method' => $method,
|
||||
'proof_path' => $proofPath,
|
||||
'items' => $items,
|
||||
'total' => cart_total(),
|
||||
]);
|
||||
$_SESSION['cart'] = [];
|
||||
header('Location: checkout.php?success=' . $orderId);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$successId = isset($_GET['success']) ? (int)$_GET['success'] : 0;
|
||||
$order = $successId ? get_order($successId) : null;
|
||||
layout_header('Checkout', 'Checkout con QR, tarjeta, transferencia y comprobante manual para LA BORGUITA.');
|
||||
?>
|
||||
<section class="py-5">
|
||||
<div class="container">
|
||||
<?php if ($order): ?>
|
||||
<div class="confirmation"><span class="eyebrow">Pedido recibido</span><h1>Pago pendiente de aprobación</h1><p>Tu pedido #<?= (int)$order['id'] ?> fue registrado por <?= h($order['customer_name']) ?>. El admin revisará el comprobante y cambiará el estado a aprobado.</p><a class="btn btn-dark" href="index.php#catalogo">Seguir comprando</a><a class="btn btn-outline-dark" href="admin.php">Ver panel admin</a></div>
|
||||
<?php elseif (!$items): ?>
|
||||
<div class="empty-state"><h1>No hay productos para pagar</h1><p>Agrega productos al carrito para continuar.</p><a class="btn btn-dark" href="index.php#catalogo">Ir al catálogo</a></div>
|
||||
<?php else: ?>
|
||||
<div class="section-heading"><span class="eyebrow">Pago manual</span><h1>Confirma tu pedido</h1><p>Elige QR, tarjeta Visa/Mastercard o transferencia. Por ahora la confirmación es manual con comprobante.</p></div>
|
||||
<?php if ($errors): ?><div class="alert alert-danger"><strong>Revisa:</strong><ul class="mb-0"><?php foreach ($errors as $error): ?><li><?= h($error) ?></li><?php endforeach; ?></ul></div><?php endif; ?>
|
||||
<div class="row g-4">
|
||||
<div class="col-lg-7">
|
||||
<form class="surface form-panel" method="post" enctype="multipart/form-data" novalidate>
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6"><label class="form-label">Nombre</label><input class="form-control" name="customer_name" required value="<?= h((string)($_POST['customer_name'] ?? '')) ?>"></div>
|
||||
<div class="col-md-6"><label class="form-label">Email</label><input class="form-control" type="email" name="customer_email" required value="<?= h((string)($_POST['customer_email'] ?? '')) ?>"></div>
|
||||
<div class="col-md-6"><label class="form-label">WhatsApp / teléfono</label><input class="form-control" name="customer_phone" required value="<?= h((string)($_POST['customer_phone'] ?? '')) ?>"></div>
|
||||
<div class="col-md-6"><label class="form-label">Método</label><select class="form-select" name="payment_method"><option value="qr">QR de pago</option><option value="card">Visa/Mastercard MX/US</option><option value="transfer">Transferencia</option></select></div>
|
||||
<div class="col-12"><label class="form-label">Notas de entrega</label><textarea class="form-control" name="delivery_notes" rows="3"><?= h((string)($_POST['delivery_notes'] ?? '')) ?></textarea></div>
|
||||
<div class="col-12"><label class="form-label">Comprobante de pago</label><input class="form-control" type="file" name="proof" accept="image/png,image/jpeg,application/pdf" required><div class="form-text">JPG, PNG o PDF hasta 8 MB. El admin aprobará manualmente.</div></div>
|
||||
</div>
|
||||
<button class="btn btn-dark btn-lg mt-4" type="submit">Enviar comprobante</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-lg-5">
|
||||
<aside class="surface summary"><div class="scan-box compact"><span>QR de pago</span><small>Coloca el QR real aquí más adelante.</small></div><h2>Resumen</h2><?php foreach ($items as $item): ?><div class="summary-line"><span><?= h($item['name']) ?> × <?= (int)$item['qty'] ?></span><strong><?= h(money((float)$item['line_total'])) ?></strong></div><?php endforeach; ?><div class="summary-total"><span>Total</span><strong><?= h(money(cart_total())) ?></strong></div></aside>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php layout_footer(); ?>
|
||||
152
includes/store.php
Normal file
152
includes/store.php
Normal file
@ -0,0 +1,152 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../db/config.php';
|
||||
|
||||
function h(string $value): string {
|
||||
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
function store_products(): array {
|
||||
return [
|
||||
'combo-24' => [
|
||||
'id' => 'combo-24',
|
||||
'name' => 'Combo Mercado 24',
|
||||
'price' => 24.99,
|
||||
'stock' => 18,
|
||||
'category' => 'Supermarket',
|
||||
'description' => 'Selección esencial para compras rápidas: snacks, bebidas y básicos del día.',
|
||||
],
|
||||
'tech-charge' => [
|
||||
'id' => 'tech-charge',
|
||||
'name' => 'Carga Tecnológica',
|
||||
'price' => 39.00,
|
||||
'stock' => 12,
|
||||
'category' => 'Tecnología',
|
||||
'description' => 'Kit tecnológico con cable premium, cargador rápido y soporte compacto.',
|
||||
],
|
||||
'fresh-box' => [
|
||||
'id' => 'fresh-box',
|
||||
'name' => 'Fresh Box Familiar',
|
||||
'price' => 54.50,
|
||||
'stock' => 9,
|
||||
'category' => 'Despensa',
|
||||
'description' => 'Caja familiar con productos de alta rotación para abastecer la semana.',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
function get_product(string $id): ?array {
|
||||
$products = store_products();
|
||||
return $products[$id] ?? null;
|
||||
}
|
||||
|
||||
function cart_items(): array {
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
$cart = $_SESSION['cart'] ?? [];
|
||||
$items = [];
|
||||
foreach ($cart as $id => $qty) {
|
||||
$product = get_product((string)$id);
|
||||
$qty = max(1, (int)$qty);
|
||||
if ($product) {
|
||||
$product['qty'] = min($qty, (int)$product['stock']);
|
||||
$product['line_total'] = $product['qty'] * (float)$product['price'];
|
||||
$items[] = $product;
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
function cart_total(): float {
|
||||
return array_reduce(cart_items(), fn($sum, $item) => $sum + (float)$item['line_total'], 0.0);
|
||||
}
|
||||
|
||||
function cart_count(): int {
|
||||
return array_reduce(cart_items(), fn($sum, $item) => $sum + (int)$item['qty'], 0);
|
||||
}
|
||||
|
||||
function money(float $amount): string {
|
||||
return '$' . number_format($amount, 2) . ' USD';
|
||||
}
|
||||
|
||||
function ensure_orders_table(): void {
|
||||
db()->exec("CREATE TABLE IF NOT EXISTS lb_orders (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
customer_name VARCHAR(120) NOT NULL,
|
||||
customer_email VARCHAR(180) NOT NULL,
|
||||
customer_phone VARCHAR(40) NOT NULL,
|
||||
delivery_notes TEXT NULL,
|
||||
payment_method VARCHAR(40) NOT NULL,
|
||||
proof_path VARCHAR(255) NULL,
|
||||
items_json JSON NOT NULL,
|
||||
total DECIMAL(10,2) NOT NULL DEFAULT 0,
|
||||
status VARCHAR(30) NOT NULL DEFAULT 'pending_review',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci");
|
||||
}
|
||||
|
||||
function create_order(array $data): int {
|
||||
ensure_orders_table();
|
||||
$stmt = db()->prepare('INSERT INTO lb_orders (customer_name, customer_email, customer_phone, delivery_notes, payment_method, proof_path, items_json, total, status) VALUES (:name, :email, :phone, :notes, :method, :proof, :items, :total, :status)');
|
||||
$stmt->execute([
|
||||
':name' => $data['customer_name'],
|
||||
':email' => $data['customer_email'],
|
||||
':phone' => $data['customer_phone'],
|
||||
':notes' => $data['delivery_notes'],
|
||||
':method' => $data['payment_method'],
|
||||
':proof' => $data['proof_path'],
|
||||
':items' => json_encode($data['items'], JSON_UNESCAPED_UNICODE),
|
||||
':total' => $data['total'],
|
||||
':status' => 'pending_review',
|
||||
]);
|
||||
return (int)db()->lastInsertId();
|
||||
}
|
||||
|
||||
function list_orders(): array {
|
||||
ensure_orders_table();
|
||||
return db()->query('SELECT * FROM lb_orders ORDER BY created_at DESC, id DESC LIMIT 50')->fetchAll();
|
||||
}
|
||||
|
||||
function get_order(int $id): ?array {
|
||||
ensure_orders_table();
|
||||
$stmt = db()->prepare('SELECT * FROM lb_orders WHERE id = :id LIMIT 1');
|
||||
$stmt->execute([':id' => $id]);
|
||||
$row = $stmt->fetch();
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
function approve_order(int $id): void {
|
||||
ensure_orders_table();
|
||||
$stmt = db()->prepare("UPDATE lb_orders SET status = 'approved', updated_at = CURRENT_TIMESTAMP WHERE id = :id");
|
||||
$stmt->execute([':id' => $id]);
|
||||
}
|
||||
|
||||
function layout_header(string $title, string $description = ''): void {
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? $description;
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
$cartCount = cart_count();
|
||||
echo '<!doctype html><html lang="es"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">';
|
||||
echo '<title>' . h($title) . ' | LA BORGUITA</title>';
|
||||
if ($projectDescription) {
|
||||
echo '<meta name="description" content="' . h($projectDescription) . '">';
|
||||
echo '<meta property="og:description" content="' . h($projectDescription) . '">';
|
||||
echo '<meta property="twitter:description" content="' . h($projectDescription) . '">';
|
||||
}
|
||||
if ($projectImageUrl) {
|
||||
echo '<meta property="og:image" content="' . h($projectImageUrl) . '">';
|
||||
echo '<meta property="twitter:image" content="' . h($projectImageUrl) . '">';
|
||||
}
|
||||
echo '<link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>';
|
||||
echo '<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">';
|
||||
echo '<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">';
|
||||
echo '<link rel="stylesheet" href="assets/css/custom.css?v=' . time() . '">';
|
||||
echo '</head><body><div id="loader" class="tech-loader"><div class="loader-card"><div class="loader-mark">LB</div><div class="loader-line"></div><p>Cargando tienda segura…</p></div></div>';
|
||||
echo '<header class="site-header sticky-top"><nav class="navbar navbar-expand-lg"><div class="container"><a class="navbar-brand brand" href="index.php"><span class="brand-logo">LB</span><span>LA BORGUITA</span></a><button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#nav" aria-controls="nav" aria-expanded="false" aria-label="Abrir navegación"><span class="navbar-toggler-icon"></span></button><div class="collapse navbar-collapse" id="nav"><ul class="navbar-nav ms-auto align-items-lg-center gap-lg-2"><li class="nav-item"><a class="nav-link" href="index.php#catalogo">Catálogo</a></li><li class="nav-item"><a class="nav-link" href="cart.php">Carrito <span class="badge text-bg-dark">' . $cartCount . '</span></a></li><li class="nav-item"><a class="nav-link" href="admin.php">Admin</a></li><li class="nav-item"><a class="btn btn-sm btn-dark" href="https://wa.me/5351746028" target="_blank" rel="noopener">WhatsApp</a></li></ul></div></div></nav></header><main>';
|
||||
}
|
||||
|
||||
function layout_footer(): void {
|
||||
echo '</main><a class="whatsapp-float" href="https://wa.me/5351746028" target="_blank" rel="noopener" aria-label="Contactar por WhatsApp">WA</a><footer class="footer"><div class="container d-flex flex-column flex-md-row justify-content-between gap-2"><span>© ' . date('Y') . ' LA BORGUITA. Precios en dólares.</span><span>Pago manual con revisión admin · Visa/Mastercard listo para integración MX/US.</span></div></footer><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script><script src="assets/js/main.js?v=' . time() . '"></script></body></html>';
|
||||
}
|
||||
223
index.php
223
index.php
@ -1,150 +1,85 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
session_start();
|
||||
require_once __DIR__ . '/includes/store.php';
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$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);
|
||||
$notice = $product['name'] . ' añadido al carrito.';
|
||||
}
|
||||
}
|
||||
|
||||
layout_header('Tienda virtual', 'LA BORGUITA: tienda virtual con catálogo, carrito, QR de pago y confirmación manual.');
|
||||
$products = store_products();
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<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=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
<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">LB</span><div><strong>LA BORGUITA</strong><small>Pagos Visa · Mastercard · Transferencia</small></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>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
</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="d-flex gap-2 mt-3">
|
||||
<input type="hidden" name="action" value="add">
|
||||
<input type="hidden" name="product_id" value="<?= h($product['id']) ?>">
|
||||
<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">Agregar</button>
|
||||
<a class="btn btn-outline-secondary" href="product.php?id=<?= h($product['id']) ?>">Detalle</a>
|
||||
</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></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(); ?>
|
||||
|
||||
34
product.php
Normal file
34
product.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
session_start();
|
||||
require_once __DIR__ . '/includes/store.php';
|
||||
$product = get_product((string)($_GET['id'] ?? ''));
|
||||
if (!$product) { http_response_code(404); layout_header('Producto no encontrado'); echo '<section class="py-5"><div class="container"><div class="alert alert-warning">Producto no encontrado.</div><a href="index.php" class="btn btn-dark">Volver</a></div></section>'; layout_footer(); exit; }
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$qty = max(1, min((int)$product['stock'], (int)($_POST['qty'] ?? 1)));
|
||||
$_SESSION['cart'][$product['id']] = min((int)$product['stock'], (int)($_SESSION['cart'][$product['id']] ?? 0) + $qty);
|
||||
header('Location: cart.php');
|
||||
exit;
|
||||
}
|
||||
layout_header($product['name'], $product['description']);
|
||||
?>
|
||||
<section class="py-5">
|
||||
<div class="container">
|
||||
<a href="index.php#catalogo" class="back-link">← Volver al catálogo</a>
|
||||
<div class="row g-4 align-items-center mt-2">
|
||||
<div class="col-lg-5"><div class="product-visual detail"><span><?= h(substr($product['name'], 0, 2)) ?></span></div></div>
|
||||
<div class="col-lg-7">
|
||||
<span class="badge subtle"><?= h($product['category']) ?></span>
|
||||
<h1 class="fw-bold mt-3"><?= h($product['name']) ?></h1>
|
||||
<p class="lead text-secondary"><?= h($product['description']) ?></p>
|
||||
<div class="price big"><?= h(money((float)$product['price'])) ?></div>
|
||||
<p class="stock mt-2">Disponible en almacén: <?= (int)$product['stock'] ?> unidades</p>
|
||||
<form method="post" class="d-flex gap-2 mt-4 checkout-strip">
|
||||
<input class="form-control" type="number" name="qty" value="1" min="1" max="<?= (int)$product['stock'] ?>" aria-label="Cantidad">
|
||||
<button class="btn btn-dark btn-lg" type="submit">Agregar al carrito</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<?php layout_footer(); ?>
|
||||
Loading…
x
Reference in New Issue
Block a user