--- a/app/Http/Controllers/Admin/ConfiguracionController.php +++ b/app/Http/Controllers/Admin/ConfiguracionController.php @@ -3,8 +3,9 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\AppSetting; +use App\Services\EcommerceLegalDocumentService; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Str; @@ -18,16 +19,97 @@ 'fontCatalog' => AppSetting::googleFontCatalog(), ]); } - public function ecommerce() - { + public function ecommerce(EcommerceLegalDocumentService $documentos) + { + $legales = []; + foreach (['terminos', 'privacidad'] as $tipo) { + $publicado = $documentos->publicado($tipo); + $borrador = $documentos->borrador($tipo); + $legales[$tipo] = [ + 'contenido' => $borrador?->contenido ?? $publicado?->contenido ?? $documentos->plantillaInicial($tipo), + 'publicado' => $publicado, + 'borrador' => $borrador, + ]; + } + return view('admin.configuracion.ecommerce', [ + 'documentosLegales' => $legales, + 'documentosLegalesDisponibles' => $documentos->disponible(), 'categoriasEcommerce' => Schema::hasTable('jerarquia_menu') ? DB::table('jerarquia_menu')->where('visible_cliente', 1)->orderBy('nombre')->get(['id', 'nombre']) : collect(), 'settings' => AppSetting::where('group', 'ecommerce')->orderBy('id')->get()->keyBy('key'), ]); + } + + /** Guardar borrador o publicar nueva versión sin tocar el formulario general de Ecommerce. */ + public function guardarDocumentoLegal(Request $request, EcommerceLegalDocumentService $documentos) + { + $data = $request->validate([ + 'tipo' => ['required', 'in:terminos,privacidad'], + 'accion' => ['required', 'in:borrador,publicar'], + 'contenido' => ['required', 'string', 'min:30', 'max:60000'], + ]); + + if (! $documentos->disponible()) { + return back()->withErrors([ + 'documentos' => 'Falta instalar la tabla ecommerce_documentos_legales. Ejecuta la migración o el SQL del paquete.', + ])->withInput(); + } + + $tipo = $data['tipo']; + $accion = $data['accion']; + $contenido = trim($data['contenido']); + + DB::transaction(function () use ($tipo, $accion, $contenido, $request) { + $tabla = DB::table('ecommerce_documentos_legales'); + $actual = now(); + if ($accion === 'borrador') { + // Un borrador por documento; la versión publicada permanece intacta. + $borrador = (clone $tabla)->where('slug', 'elpapas')->where('tipo', $tipo) + ->where('estado', 'BORRADOR')->orderByDesc('id')->lockForUpdate()->first(); + if ($borrador) { + (clone $tabla)->where('id', $borrador->id)->update([ + 'contenido' => $contenido, 'updated_at' => $actual, 'usuario_id' => $request->user()?->id, + ]); + } else { + $tabla->insert([ + 'slug' => 'elpapas', 'tipo' => $tipo, 'estado' => 'BORRADOR', + 'contenido' => $contenido, 'usuario_id' => $request->user()?->id, + 'created_at' => $actual, 'updated_at' => $actual, + ]); + } + } else { + // Nunca sobrescribimos versiones anteriores aceptadas por compradores. + $id = $tabla->insertGetId([ + 'slug' => 'elpapas', 'tipo' => $tipo, 'estado' => 'PUBLICADO', + 'contenido' => $contenido, 'publicado_at' => $actual, + 'usuario_id' => $request->user()?->id, + 'created_at' => $actual, 'updated_at' => $actual, + ]); + (clone $tabla)->where('id', $id)->update(['version' => $actual->format('Y-m-d') . '-v' . $id]); + (clone $tabla)->where('slug', 'elpapas')->where('tipo', $tipo) + ->where('estado', 'BORRADOR')->delete(); + } + }); + + return redirect()->route('admin.configuracion.ecommerce', [], 303) + ->with('success', $accion === 'publicar' + ? ($tipo === 'terminos' ? 'Términos publicados con nueva versión.' : 'Política de privacidad publicada con nueva versión.') + : 'Borrador guardado. La página pública todavía muestra la versión publicada.'); + } + + /** Convierte Markdown a HTML filtrado en el servidor, para previsualizar antes de publicar. */ + public function previsualizarDocumentoLegal(Request $request, EcommerceLegalDocumentService $documentos) + { + $data = $request->validate([ + 'tipo' => ['required', 'in:terminos,privacidad'], + 'contenido' => ['required', 'string', 'max:60000'], + ]); + + return response()->json(['ok' => true, 'html' => $documentos->aHtml($data['contenido'])]); } public function updateEcommerce(Request $request) { --- a/app/Http/Controllers/PublicEcommerceController.php +++ b/app/Http/Controllers/PublicEcommerceController.php @@ -3,8 +3,9 @@ namespace App\Http\Controllers; use App\Models\AppSetting; use App\Services\MercadoPagoService; +use App\Services\EcommerceLegalDocumentService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; @@ -32,9 +33,9 @@ return view('public.ecommerce', [ 'slug' => $slug, 'brand' => $brand, 'legalUrls' => $this->legalUrls($slug), - 'legalVersion' => self::VERSION_TERMINOS, + 'legalVersion' => app(EcommerceLegalDocumentService::class)->versionTerminos($slug, self::VERSION_TERMINOS), ]); } public function terminos(string $slug = 'elpapas') @@ -48,14 +49,19 @@ } private function paginaLegal(string $slug, string $tipo) { + $documentos = app(EcommerceLegalDocumentService::class); + $publicado = $documentos->publicado($tipo, $slug); + return view('public.ecommerce-legal', [ 'slug' => $slug, 'tipo' => $tipo, 'brand' => $this->brandData(Str::headline(str_replace('-', ' ', $slug)), false), 'legalUrls' => $this->legalUrls($slug), - 'legalVersion' => self::VERSION_TERMINOS, + 'legalVersion' => $publicado?->version ?? self::VERSION_TERMINOS, + 'legalPublishedAt' => $publicado?->publicado_at, + 'legalHtml' => $publicado ? $documentos->aHtml($publicado->contenido) : null, ]); } private function legalUrls(string $slug): array @@ -250,11 +256,13 @@ } public function crearPedido(Request $request, string $slug, MercadoPagoService $mercadoPago): JsonResponse { + // La versión vigente debe corresponder a la que aceptó el comprador. + $versionTerminos = app(EcommerceLegalDocumentService::class)->versionTerminos($slug, self::VERSION_TERMINOS); $data = $request->validate([ 'acepta_terminos' => ['required', 'accepted'], - 'terminos_version' => ['required', 'string', 'in:' . self::VERSION_TERMINOS], + 'terminos_version' => ['required', 'string', 'in:' . $versionTerminos], 'cliente.nombre' => ['required', 'string', 'max:120'], 'cliente.telefono' => ['required', 'string', 'max:40'], 'cliente.email' => ['nullable', 'email', 'max:120'], 'cliente.direccion' => ['nullable', 'string', 'max:255'], @@ -306,9 +314,9 @@ ], 503); } try { - $resultado = DB::transaction(function () use ($data, $slug, $clienteId, $tipoEntrega, $costoDespacho, $minimoDespacho) { + $resultado = DB::transaction(function () use ($data, $slug, $clienteId, $tipoEntrega, $costoDespacho, $minimoDespacho, $versionTerminos) { $subtotal = 0.0; $itemsCalculados = []; foreach ($data['items'] as $item) { @@ -437,9 +445,9 @@ 'total' => $subtotal + $costoDespacho, 'metadata_json' => json_encode([ 'aceptacion_legal' => [ 'aceptado' => true, - 'version_terminos' => self::VERSION_TERMINOS, + 'version_terminos' => $versionTerminos, 'aceptado_at' => now('America/Santiago')->toIso8601String(), 'politica_privacidad_informada' => true, 'url_terminos' => $this->legalUrls($slug)['terminos'], 'url_privacidad' => $this->legalUrls($slug)['privacidad'], --- /dev/null +++ b/app/Services/EcommerceLegalDocumentService.php @@ -0,0 +1,115 @@ +disponible() || ! in_array($tipo, ['terminos', 'privacidad'], true)) { + return null; + } + + return DB::table('ecommerce_documentos_legales') + ->where('slug', $slug) + ->where('tipo', $tipo) + ->where('estado', 'PUBLICADO') + ->orderByDesc('id') + ->first(); + } + + public function borrador(string $tipo, string $slug = 'elpapas'): ?object + { + if (! $this->disponible() || ! in_array($tipo, ['terminos', 'privacidad'], true)) { + return null; + } + + return DB::table('ecommerce_documentos_legales') + ->where('slug', $slug) + ->where('tipo', $tipo) + ->where('estado', 'BORRADOR') + ->orderByDesc('id') + ->first(); + } + + public function versionTerminos(string $slug, string $fallback): string + { + return (string) ($this->publicado('terminos', $slug)?->version ?? $fallback); + } + + /** El Markdown queda escapado y no ejecuta HTML arbitrario ni enlaces peligrosos. */ + public function aHtml(string $markdown): string + { + return Str::markdown($markdown, [ + 'html_input' => 'strip', + 'allow_unsafe_links' => false, + ]); + } + + /** Texto inicial basado en las cláusulas que ya existían en ecommerce-legal.blade.php. */ + public function plantillaInicial(string $tipo): string + { + if ($tipo === 'privacidad') { + return <<<'MD' +## 1. Responsable del tratamiento +El vendedor identificado en esta página es responsable del tratamiento de los datos recabados para la compra, atención y entrega de pedidos. El proveedor tecnológico VASE opera la plataforma conforme a sus acuerdos con el comercio. + +## 2. Datos que se solicitan +Nombre, teléfono, correo electrónico cuando se indique, dirección de entrega cuando corresponda, indicaciones voluntarias del pedido, productos seleccionados y antecedentes técnicos necesarios para seguridad y auditoría, como fecha, dirección IP y agente de usuario. El carrito y el identificador de un pago en curso pueden mantenerse temporalmente en el navegador. + +## 3. Finalidades y fundamento +Procesar compras, cobrar, coordinar preparación y entrega, atender reclamos, prevenir fraudes, resguardar la operación y cumplir deberes tributarios o legales. Los datos necesarios para ejecutar una compra se tratan para esa finalidad; el envío de publicidad no se incluye como condición del pedido ni se presupone autorizado. + +## 4. Destinatarios y proveedores +El personal autorizado puede acceder a la información indispensable para preparar o atender el pedido. La pasarela Mercado Pago recibe los datos necesarios para gestionar el cobro. Prestadores de hosting y soporte técnico pueden tratar datos para operar el servicio según las instrucciones y obligaciones correspondientes. + +## 5. Conservación y medidas de seguridad +Se conservarán datos durante los periodos necesarios para tramitar compras y reclamaciones y cumplir obligaciones legales aplicables, limitando el acceso a personal autorizado. El responsable debe establecer plazos específicos de conservación, eliminación y respuesta a incidentes conforme a la ley vigente. + +## 6. Derechos de las personas +Podrás solicitar acceso, rectificación y los demás derechos que correspondan conforme a la normativa de protección de datos aplicable en Chile, contactando al responsable por el correo indicado. La Ley N.º 21.719 comienza a regir el 1 de diciembre de 2026, salvo modificaciones legales posteriores. + +## 7. Solicitudes y cambios +Para realizar consultas o ejercer tus derechos, utiliza el correo de contacto publicado al comienzo. Las actualizaciones materiales de esta política deberán publicarse con su versión actualizada. +MD; + } + + return <<<'MD' +## 1. Cómo comprar +Selecciona los productos y sus opciones, revisa cantidades, modalidad de entrega, costo de despacho y total antes de pagar. Los precios se expresan en pesos chilenos (CLP). El sistema validará los precios y la disponibilidad al procesar el pedido. + +## 2. Pago y confirmación +El pago en línea se procesa mediante Mercado Pago. La creación del pedido no equivale a pago aprobado. Su aprobación se verifica en el servidor con la pasarela. Si una operación queda pendiente, evita pagar dos veces y contacta al negocio para confirmar su estado. + +## 3. Entrega, retiro y plazos +Las modalidades disponibles se muestran durante el checkout y pueden incluir retiro en local, despacho a domicilio o consumo en el local. El costo de despacho y el total se muestran antes de pagar. Las condiciones de reparto dependen de la dirección informada. Consulta los plazos y la dirección de retiro comunicados por el comercio durante la compra. + +## 4. Rectificaciones y cancelaciones +Para modificar o solicitar la cancelación de un pedido, comunícate cuanto antes mediante el correo de contacto indicado. La posibilidad de modificarlo depende del estado de preparación y entrega, sin perjuicio de los derechos legales aplicables. Ante cobros duplicados, pagos aprobados sin entrega o errores del comercio, se revisará el caso y corresponderá la solución que establece la ley. + +## 5. Derecho a retracto +La legislación chilena contempla el derecho a retracto en compras a distancia en los casos y plazos previstos legalmente. Ciertos alimentos preparados o perecibles de rápido deterioro pueden quedar excluidos, conforme al Decreto N.º 52, cuando corresponda a la naturaleza del producto. Las exclusiones se advierten junto al precio y descripción de los productos marcados como perecibles en la tienda. + +**La exclusión por arrepentimiento no elimina los derechos del cliente por productos defectuosos, pedidos incorrectos o incumplimientos de lo ofrecido.** Si el producto no está sujeto a una exclusión legal, se aplica el régimen de retracto correspondiente. + +## 6. Reclamos y soluciones +Si faltan productos, recibes un pedido incorrecto o existe otro incumplimiento, solicita asistencia por el canal de contacto señalado en esta página, idealmente indicando el número de pedido y una descripción del problema. Se analizará la entrega, reposición o devolución que proceda conforme a la normativa. + +## 7. Datos personales +Los datos de contacto y entrega se utilizan para tramitar el pedido, verificar el pago y cumplir obligaciones legales. Consulta nuestra Política de privacidad para más información. + +## 8. Marco normativo +Estas condiciones se interpretan respetando la Ley N.º 19.496, el Reglamento de Comercio Electrónico y demás normativa chilena aplicable. Ninguna disposición limita derechos irrenunciables de consumidores. +MD; + } +} --- /dev/null +++ b/database/migrations/2026_11_16_180000_create_ecommerce_documentos_legales_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('slug', 80)->default('elpapas'); + $table->string('tipo', 20); + $table->string('estado', 16)->default('BORRADOR'); + $table->longText('contenido'); + $table->string('version', 64)->nullable(); + $table->timestamp('publicado_at')->nullable(); + $table->unsignedBigInteger('usuario_id')->nullable(); + $table->timestamps(); + $table->index(['slug', 'tipo', 'estado', 'id'], 'ecom_legales_busqueda'); + }); + } + + public function down(): void + { + Schema::dropIfExists('ecommerce_documentos_legales'); + } +}; --- /dev/null +++ b/instalacion/01_documentos_legales.sql @@ -0,0 +1,17 @@ +-- Ejecutar UNA SOLA VEZ en la base de datos activa vasecles_vase. +-- NO ejecutar el dump completo de producción ni borrar tablas existentes. +-- Alternativa: ejecutar php artisan migrate --force con la migración incluida. +CREATE TABLE IF NOT EXISTS `ecommerce_documentos_legales` ( + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `slug` VARCHAR(80) NOT NULL DEFAULT 'elpapas', + `tipo` VARCHAR(20) NOT NULL, + `estado` VARCHAR(16) NOT NULL DEFAULT 'BORRADOR', + `contenido` LONGTEXT NOT NULL, + `version` VARCHAR(64) DEFAULT NULL, + `publicado_at` TIMESTAMP NULL DEFAULT NULL, + `usuario_id` BIGINT UNSIGNED DEFAULT NULL, + `created_at` TIMESTAMP NULL DEFAULT NULL, + `updated_at` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `ecom_legales_busqueda` (`slug`, `tipo`, `estado`, `id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; --- a/public/css/ecommerce-legal-pages.css +++ b/public/css/ecommerce-legal-pages.css @@ -1 +1 @@ -*{box-sizing:border-box}body{margin:0;background:#fbf7ef;color:#3c2b20;font:16px/1.65 system-ui,-apple-system,"Segoe UI",Arial,sans-serif}a{color:#77391c}a:hover{color:#a35d30}.legal-header{background:linear-gradient(120deg,#763216,#a45c29);color:white}.legal-top{max-width:880px;margin:auto;min-height:76px;padding:16px 22px;display:flex;align-items:center;justify-content:space-between;gap:16px;font-weight:800}.legal-back{color:white!important;text-decoration:none;background:#ffffff21;padding:8px 13px;border:1px solid #ffffff44;border-radius:30px}.legal-main{max-width:880px;margin:28px auto 65px;padding:22px 32px 45px;background:white;border:1px solid #eee2d5;border-radius:23px;box-shadow:0 14px 35px #6b3a1810}.legal-eyebrow{font-size:.75rem;text-transform:uppercase;color:#99632d;letter-spacing:.12em;font-weight:900}.legal-main h1{font-size:clamp(1.8rem,5vw,2.5rem);line-height:1.18;color:#5a2811;margin:8px 0}.legal-updated{color:#87776b;font-size:.88rem}.legal-nav{display:flex;flex-wrap:wrap;gap:9px;border-bottom:1px solid #eee2d5;padding:14px 0 24px;margin-bottom:25px}.legal-nav a{padding:9px 14px;border-radius:30px;border:1px solid #e9d7be;text-decoration:none;font-weight:700;font-size:.87rem}.legal-nav [aria-current=page]{background:#6b2f16;color:white;border-color:#6b2f16}.legal-main section{margin:27px 0}.legal-main h2{color:#663015;font-size:1.23rem;margin:0 0 9px}.legal-main p{margin:8px 0;color:#4f4036}.legal-identification{background:#fff9f0;border:1px solid #f0dbc1;padding:20px;border-radius:14px}.legal-identification dl{display:grid;grid-template-columns:165px 1fr;gap:7px 13px;margin:0}.legal-identification dt{font-weight:800}.legal-identification dd{margin:0;overflow-wrap:anywhere}.legal-incomplete{background:#fff0da;color:#8b3d11!important;padding:11px 13px;border-left:4px solid #b76f2e;border-radius:6px}.legal-foot{margin-top:36px;padding-top:23px;border-top:1px solid #eee2d5;font-weight:800}.legal-footer{text-align:center;padding:22px;color:#84756b;font-size:.82rem}@media(max-width:650px){.legal-main{margin:10px 12px 30px;padding:21px 18px;border-radius:15px}.legal-identification dl{grid-template-columns:1fr;gap:1px}.legal-identification dd{margin-bottom:9px}.legal-top{padding:13px 15px;font-size:.82rem}} +*{box-sizing:border-box}body{margin:0;background:#fbf7ef;color:#3c2b20;font:16px/1.65 system-ui,-apple-system,"Segoe UI",Arial,sans-serif}a{color:#77391c}a:hover{color:#a35d30}.legal-header{background:linear-gradient(120deg,#763216,#a45c29);color:white}.legal-top{max-width:880px;margin:auto;min-height:76px;padding:16px 22px;display:flex;align-items:center;justify-content:space-between;gap:16px;font-weight:800}.legal-back{color:white!important;text-decoration:none;background:#ffffff21;padding:8px 13px;border:1px solid #ffffff44;border-radius:30px}.legal-main{max-width:880px;margin:28px auto 65px;padding:22px 32px 45px;background:white;border:1px solid #eee2d5;border-radius:23px;box-shadow:0 14px 35px #6b3a1810}.legal-eyebrow{font-size:.75rem;text-transform:uppercase;color:#99632d;letter-spacing:.12em;font-weight:900}.legal-main h1{font-size:clamp(1.8rem,5vw,2.5rem);line-height:1.18;color:#5a2811;margin:8px 0}.legal-updated{color:#87776b;font-size:.88rem}.legal-nav{display:flex;flex-wrap:wrap;gap:9px;border-bottom:1px solid #eee2d5;padding:14px 0 24px;margin-bottom:25px}.legal-nav a{padding:9px 14px;border-radius:30px;border:1px solid #e9d7be;text-decoration:none;font-weight:700;font-size:.87rem}.legal-nav [aria-current=page]{background:#6b2f16;color:white;border-color:#6b2f16}.legal-main section{margin:27px 0}.legal-main h2{color:#663015;font-size:1.23rem;margin:0 0 9px}.legal-main p{margin:8px 0;color:#4f4036}.legal-identification{background:#fff9f0;border:1px solid #f0dbc1;padding:20px;border-radius:14px}.legal-identification dl{display:grid;grid-template-columns:165px 1fr;gap:7px 13px;margin:0}.legal-identification dt{font-weight:800}.legal-identification dd{margin:0;overflow-wrap:anywhere}.legal-incomplete{background:#fff0da;color:#8b3d11!important;padding:11px 13px;border-left:4px solid #b76f2e;border-radius:6px}.legal-foot{margin-top:36px;padding-top:23px;border-top:1px solid #eee2d5;font-weight:800}.legal-footer{text-align:center;padding:22px;color:#84756b;font-size:.82rem}.legal-content h2,.legal-content h3{color:#663015;margin:26px 0 9px}.legal-content h2{font-size:1.25rem}.legal-content h3{font-size:1.05rem}.legal-content li{margin:7px 0}.legal-content a{text-decoration:underline;text-underline-offset:3px}.legal-content p{overflow-wrap:anywhere}.legal-content blockquote{border-left:4px solid #ddb47c;background:#fff9ee;padding:12px 17px;margin:14px 0}.legal-content img{max-width:100%;height:auto}@media(max-width:650px){.legal-main{margin:10px 12px 30px;padding:21px 18px;border-radius:15px}.legal-identification dl{grid-template-columns:1fr;gap:1px}.legal-identification dd{margin-bottom:9px}.legal-top{padding:13px 15px;font-size:.82rem}} --- /dev/null +++ b/public/css/elpapas-20261116.css @@ -0,0 +1,196 @@ +/* El Papa's · Ajustes 16-11-2026 · Solo tienda pública. + Capa final aislada: no modifica POS, pagos, pedidos ni formularios. */ +.ecommerce-body .ecommerce-storefront .store-menu-bar{ + position:relative;z-index:30;display:flex;align-items:center; + width:min(1200px,calc(100% - 36px))!important;margin:0 auto 31px!important; + overflow:visible!important; +} +.ecommerce-body .ecommerce-storefront .store-category-tabs{display:none!important} +.ecommerce-body .ecommerce-storefront .store-tools{ + display:flex!important;align-items:center!important;gap:15px!important; + flex:1 1 100%!important;width:100%!important;max-width:none!important; + min-width:0;margin:0!important; +} +.ecommerce-body .ecommerce-storefront .store-category-picker{ + position:relative!important;display:block!important;width:clamp(240px,30%,335px)!important; + min-width:230px!important;flex:0 1 335px!important; +} +.ecommerce-body .ecommerce-storefront .store-category-trigger{ + width:100%!important;min-height:58px!important;padding:9px 14px!important; + display:flex!important;align-items:center!important;gap:12px!important; + border:1px solid #e9d3b9!important;border-radius:17px!important; + background:#fffdf9!important;color:#633019!important; + box-shadow:0 7px 20px rgba(108,65,31,.06)!important; + cursor:pointer;transition:border-color .2s,box-shadow .2s; +} +.ecommerce-body .ecommerce-storefront .store-category-trigger:is(:hover,:focus-visible), +.ecommerce-body .ecommerce-storefront .store-category-picker.open .store-category-trigger{ + border-color:#d7a267!important;box-shadow:0 0 0 4px rgba(244,179,76,.13)!important; +} +.ecommerce-body .ecommerce-storefront .store-category-trigger>svg:first-child{flex:0 0 19px;color:#914d26} +.ecommerce-body .ecommerce-storefront .store-category-trigger-text{display:flex;flex-direction:column;min-width:0;flex:1;text-align:left;gap:1px} +.ecommerce-body .ecommerce-storefront .store-category-label{ + font-size:.69rem!important;line-height:1.2;font-weight:700;letter-spacing:.025em;color:#997461; +} +.ecommerce-body .ecommerce-storefront #categoryCurrent{ + display:block;min-width:0;font-weight:900!important;font-size:.99rem;white-space:nowrap; + overflow:hidden;text-overflow:ellipsis;color:#653016; +} +.ecommerce-body .ecommerce-storefront .store-category-chevron{flex:0 0 18px;transition:transform .2s} +.ecommerce-body .ecommerce-storefront .store-category-menu{ + display:flex!important;flex-direction:column!important;gap:7px!important;position:absolute!important; + top:calc(100% + 9px)!important;left:0!important;right:auto!important;width:min(390px,calc(100vw - 30px))!important; + padding:11px!important;z-index:150!important;max-height:min(440px,68vh); + background:#fff!important;border:1px solid #e9dacc!important;border-radius:17px!important; + box-shadow:0 18px 48px rgba(71,39,20,.20)!important; + overflow:hidden!important;visibility:hidden;opacity:0;pointer-events:none; + transform:translateY(-6px);transition:opacity .16s,transform .16s,visibility .16s; +} +.ecommerce-body .ecommerce-storefront .store-category-picker.open .store-category-menu{ + visibility:visible!important;opacity:1!important;pointer-events:auto;transform:translateY(0)!important; +} +.ecommerce-body .ecommerce-storefront .store-category-search{ + display:flex;align-items:center;gap:8px;padding:5px 11px;min-height:44px; + border:1px solid #e9dacc;border-radius:11px;background:#fdf9f4;color:#8d5e40; +} +.ecommerce-body .ecommerce-storefront .store-category-search input{ + width:100%;height:34px;border:0!important;outline:0!important;box-shadow:none!important; + background:transparent!important;color:#633019;font:inherit;font-size:.89rem; +} +.ecommerce-body .ecommerce-storefront .store-category-options{ + display:flex;flex-direction:column;gap:3px;min-height:0;max-height:320px;overflow-y:auto;overscroll-behavior:contain; + scrollbar-width:thin;padding-right:2px; +} +.ecommerce-body .ecommerce-storefront .store-category-option{ + width:100%;display:flex!important;justify-content:space-between;align-items:center;gap:10px; + border:0!important;border-radius:10px!important;padding:11px 13px!important; + font-size:.9rem!important;font-weight:750!important;line-height:1.35!important;cursor:pointer; + background:transparent!important;color:#61321c!important; +} +.ecommerce-body .ecommerce-storefront .store-category-option:is(:hover,:focus-visible){background:#fff3e2!important;outline:none} +.ecommerce-body .ecommerce-storefront .store-category-option.active{background:#f8e1bd!important;color:#5f2c10!important} +.ecommerce-body .ecommerce-storefront .store-category-empty{padding:13px!important;color:#846a58;text-align:center;font-size:.88rem} +.ecommerce-body .ecommerce-storefront .store-search{ + min-width:0;flex:1 1 auto;max-width:none;width:auto!important;min-height:58px!important; + padding-inline:17px!important;border-radius:17px!important; +} +.ecommerce-body .ecommerce-storefront .store-search input{font-size:.93rem!important} + +/* Tarjetas uniformes: precio en una zona propia y CTA con respiración. */ +.ecommerce-body .ecommerce-storefront .product-card{ + padding:12px!important;border-radius:23px!important; + box-shadow:0 10px 25px rgba(98,56,23,.09)!important; +} +.ecommerce-body .ecommerce-storefront .product-img{ + height:245px!important;min-height:245px!important;max-height:245px!important;border-radius:17px!important; + background:#fff8ef!important; +} +.ecommerce-body .ecommerce-storefront .product-img img{ + padding:4px!important;object-fit:contain!important;object-position:center center!important; +} +.ecommerce-body .ecommerce-storefront .product-info{padding:16px 8px 5px!important;gap:8px!important} +.ecommerce-body .ecommerce-storefront .product-info h3{font-size:1.22rem!important} +.ecommerce-body .ecommerce-storefront .product-price-row{ + display:flex!important;align-items:center!important;gap:11px!important;justify-content:space-between!important; + padding:15px 0 1px!important;margin-top:auto!important; + border-top:1px solid #f0e4d7;flex-wrap:nowrap!important; +} +.ecommerce-body .ecommerce-storefront .product-price-wrap{ + display:flex;flex-direction:column;gap:2px;align-items:flex-start;min-width:0; +} +.ecommerce-body .ecommerce-storefront .product-price-wrap small{ + color:#8c7160;font-size:.72rem;font-weight:700;letter-spacing:.025em; +} +.ecommerce-body .ecommerce-storefront .product-price{ + font-size:clamp(1.1rem,1.6vw,1.34rem)!important;font-weight:950!important; + white-space:nowrap!important;color:#642d16!important; +} +.ecommerce-body .ecommerce-storefront .product-add{ + display:inline-flex!important;gap:7px!important;align-items:center!important;justify-content:center!important; + min-height:46px!important;padding:11px 15px!important;border-radius:13px!important; + background:#f6b643!important;color:#512909!important; + font-size:.9rem!important;box-shadow:0 4px 0 rgba(114,60,17,.06)!important; +} + +/* Foto protagonista: cubre el encabezado del modal; título legible sobre degradado. */ +.ecommerce-body .ecommerce-storefront .product-modal-card{ + width:min(660px,calc(100% - 24px))!important; + max-height:calc(100dvh - 28px)!important;border-radius:24px!important;overflow:auto!important; +} +.ecommerce-body .ecommerce-storefront .modal-product-summary{ + position:relative!important;isolation:isolate;display:block!important; + height:320px!important;min-height:320px!important;max-height:none!important; + padding:0!important;margin:0!important;overflow:hidden!important; + border:0!important;border-radius:22px 22px 0 0!important; + background:linear-gradient(145deg,#aa753e,#4c2517)!important; +} +.ecommerce-body .ecommerce-storefront .modal-product-img{ + position:absolute!important;inset:0!important;display:flex!important;align-items:center;justify-content:center; + flex:none!important;width:100%!important;height:100%!important; + min-height:100%!important;max-height:none!important;min-width:100%!important; + aspect-ratio:auto!important;border-radius:0!important;margin:0!important; + padding:0!important;overflow:hidden!important;background:transparent!important; +} +.ecommerce-body .ecommerce-storefront .modal-product-img img{ + display:block!important;width:100%!important;height:100%!important;max-width:none!important; + max-height:none!important;object-fit:cover!important;object-position:center 45%!important; + margin:0!important;padding:0!important;border-radius:0!important; + background:transparent!important;transform:none!important;filter:none!important; +} +.ecommerce-body .ecommerce-storefront .modal-product-img .product-placeholder{font-size:5rem} +.ecommerce-body .ecommerce-storefront .modal-product-summary::after{ + content:""!important;position:absolute;z-index:1;inset:0;pointer-events:none; + display:block!important;background:linear-gradient(180deg,rgba(26,11,4,.05) 20%,rgba(26,11,4,.22) 46%,rgba(26,11,4,.9) 100%)!important; +} +.ecommerce-body .ecommerce-storefront .modal-product-title{ + position:absolute!important;z-index:2;left:0;right:0;bottom:0; + display:flex!important;flex-direction:column!important;gap:5px!important; + min-width:0;padding:34px 26px 22px!important; + text-shadow:0 2px 9px rgba(0,0,0,.43); +} +.ecommerce-body .ecommerce-storefront .modal-product-title h2{ + font-size:clamp(1.65rem,4vw,2.15rem)!important;line-height:1.1!important; + font-weight:900!important;letter-spacing:-.035em!important;color:#fff!important;margin:0!important; +} +.ecommerce-body .ecommerce-storefront .modal-product-title p{ + color:#fff9f0!important;line-height:1.45!important;font-size:.96rem!important; + margin:3px 0 0!important;max-width:90%; +} +.ecommerce-body .ecommerce-storefront .modal-product-title strong{ + display:inline-block;align-self:flex-start;margin-top:4px!important; + font-size:1.43rem!important;line-height:1.25!important;font-weight:950!important;color:#fff!important; +} +.ecommerce-body .ecommerce-storefront .modal-close{ + position:sticky!important;z-index:20!important;top:12px!important;right:12px!important; + float:right!important;margin:12px 12px -54px 0!important; + background:#fff!important;color:#3f2416!important;border:0!important; + box-shadow:0 4px 15px rgba(0,0,0,.13)!important; +} +.ecommerce-body .ecommerce-storefront .modal-product-body{padding:15px 20px 22px!important} +.ecommerce-body .ecommerce-storefront .modal-product-body>.ecom-retracto-notice{ + margin:0 0 10px!important;display:block!important; +} +@media(max-width:950px){ + .ecommerce-body .ecommerce-storefront .product-img{height:230px!important;min-height:230px!important;max-height:230px!important} +} +@media(max-width:720px){ + .ecommerce-body .ecommerce-storefront .store-menu-bar{width:calc(100% - 24px)!important;margin-bottom:22px!important} + .ecommerce-body .ecommerce-storefront .store-tools{flex-wrap:wrap!important;gap:10px!important} + .ecommerce-body .ecommerce-storefront .store-category-picker{flex:1 1 240px!important;width:100%!important;min-width:0!important} + .ecommerce-body .ecommerce-storefront .store-search{flex:1 1 240px!important;width:100%!important} + .ecommerce-body .ecommerce-storefront .product-img{height:195px!important;min-height:195px!important;max-height:195px!important} + .ecommerce-body .ecommerce-storefront .modal-product-summary{height:275px!important;min-height:275px!important} + .ecommerce-body .ecommerce-storefront .modal-product-title{padding:35px 19px 17px!important} + .ecommerce-body .ecommerce-storefront .modal-product-body{padding:12px 15px 19px!important} +} +@media(max-width:510px){ + .ecommerce-body .ecommerce-storefront .product-img{height:235px!important;min-height:235px!important;max-height:235px!important} + .ecommerce-body .ecommerce-storefront .modal-product-summary{height:250px!important;min-height:250px!important} + .ecommerce-body .ecommerce-storefront .modal-product-title h2{font-size:1.55rem!important} + .ecommerce-body .ecommerce-storefront .modal-product-title p{font-size:.84rem!important} + .ecommerce-body .ecommerce-storefront .modal-product-title strong{font-size:1.22rem!important} +} +@media(prefers-reduced-motion:reduce){ + .ecommerce-body .ecommerce-storefront .store-category-menu, + .ecommerce-body .ecommerce-storefront .store-category-trigger{transition:none!important} +} --- a/public/js/ecommerce-public.js +++ b/public/js/ecommerce-public.js @@ -34,11 +34,15 @@ state.query = ev.target.value.trim().toLowerCase(); renderProducts(); }); $('categoryTrigger')?.addEventListener('click', toggleCategoryMenu); + $('categorySearch')?.addEventListener('input', renderCategories); document.addEventListener('click', (ev) => { const picker = $('categoryPicker'); if (picker && !picker.contains(ev.target)) closeCategoryMenu(); + }); + document.addEventListener('keydown', (ev) => { + if (ev.key === 'Escape') closeCategoryMenu(); }); $('btnOpenCart')?.addEventListener('click', openCart); $('btnCloseCart')?.addEventListener('click', closeCart); $('cartBackdrop')?.addEventListener('click', closeCart); @@ -87,36 +91,32 @@ } } function renderCategories() { - const menu = $('categoryMenu'); + const optionsContainer = $('categoryOptions'); const current = $('categoryCurrent'); - if (!menu || !current) return; - - const options = [ - { id: 'todos', nombre: 'Todo el menú' }, - ...state.categorias, - ]; - + if (!optionsContainer || !current) return; + + const options = [{ id: 'todos', nombre: 'Todo el menú' }, ...state.categorias]; const active = options.find(cat => String(cat.id) === String(state.activeCategory)) || options[0]; current.textContent = active.nombre; - menu.innerHTML = options.map(cat => ` - `).join(''); - - const tabs = $('categoryTabs'); - if (tabs) { - tabs.innerHTML = options.map(cat => ``).join(''); - } - [menu, tabs].filter(Boolean).forEach(group => group.querySelectorAll('[data-category-id]').forEach(btn => { + const search = ($('categorySearch')?.value || '').trim().normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase(); + const filtered = options.filter(cat => String(cat.nombre).normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase().includes(search)); + optionsContainer.innerHTML = filtered.length ? filtered.map(cat => ` + `).join('') : '

No hay categorías con ese nombre.

'; + + optionsContainer.querySelectorAll('[data-category-id]').forEach(btn => { btn.addEventListener('click', () => { state.activeCategory = btn.dataset.categoryId; + if ($('categorySearch')) $('categorySearch').value = ''; renderCategories(); renderProducts(); closeCategoryMenu(); + $('categoryTrigger')?.focus(); }); - })); + }); } function toggleCategoryMenu() { const picker = $('categoryPicker'); @@ -124,8 +124,13 @@ if (!picker || !trigger) return; const opening = !picker.classList.contains('open'); picker.classList.toggle('open', opening); trigger.setAttribute('aria-expanded', opening ? 'true' : 'false'); + if (opening) { + if ($('categorySearch')) $('categorySearch').value = ''; + renderCategories(); + $('categorySearch')?.focus(); + } } function closeCategoryMenu() { $('categoryPicker')?.classList.remove('open'); @@ -175,9 +180,9 @@

${escapeHtml(p.nombre)}

${escapeHtml(p.descripcion || 'Elige tus opciones favoritas.')}

${p.retracto_excluido ? '

Alimento perecible: sin retracto por arrepentimiento.

' : ''}
- ${money(p.precio_publico)} + Precio${money(p.precio_publico)} Agregar
`; @@ -239,12 +244,12 @@

${escapeHtml(p.nombre)}

${escapeHtml(p.descripcion || '')}

${money(p.precio_publico)} - ${p.retracto_excluido ? '

Alimento preparado/perecible: excluido del retracto por arrepentimiento. Se mantienen tus derechos ante fallas o incumplimientos.

' : ''}