¿Dudas en tu compra? ¡Contáctanos! Asesoría especializada. Lun–Vie 9:00–18:00 | Contacto | WhatsApp 0

Inicio · Llantas · Comprar

BD Distribuidora

En línea

¡Hola! 👋

¿En qué puedo ayudarte hoy?

Ahora
' + logoImg + '

REFERENCIADOR PARA PAGO O TRANSFERENCIA

' + '

Depósito en ventanilla / Transferencia bancaria

' + '

Fecha de emisión: ' + fechaEmision + '

' + clienteBlock + entregaBlock + '' + rows + '
ProductoCant.Subtotal
' + (selectedEnvio && selectedEnvio.rate ? '
Envío (' + escapeHtml(selectedEnvio.rate.carrier) + ')' + formatMoney(selectedEnvio.rate.price) + '
' : '') + '
TOTAL A PAGAR' + (selectedEnvio && selectedEnvio.rate && !order.aCotizar ? formatMoney(order.total + selectedEnvio.rate.price) : totalStr) + '
' + '

Referencia de pago: ' + escapeHtml(refVal) + '

' + '

Datos para depósito o transferencia

' + '

Titular: ' + escapeHtml(BANK.titular) + '

' + '

Banco: ' + escapeHtml(BANK.banco) + '

' + (BANK.cuenta ? '

Cuenta: ' + escapeHtml(BANK.cuenta) + '

' : '') + (BANK.clabe ? '

CLABE: ' + escapeHtml(BANK.clabe) + '

' : '') + '
' + '

Envía este comprobante a contacto@bddistribuidora.com o por WhatsApp para confirmar tu pedido.

' + '

BD Distribuidora · Guadalajara

' + '
' + '' + ' Solicitar factura' + '
'; var blob = new Blob([html], { type: 'text/html;charset=utf-8' }); var a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'comprobante-llantas-ormak-carrito.html'; a.click(); URL.revokeObjectURL(a.href); var summary = { items: order.items.map(function(it) { return { name: it.name, quantity: it.quantity, subtotal: it.subtotal, subtotalStr: it.aCotizar ? 'A cotizar' : formatMoney(it.subtotal) }; }), total: order.total, totalStr: order.aCotizar ? 'A cotizar (te contactaremos)' : formatMoney(order.total) }; enviarComprobantePorCorreo(html, refVal, clientData, summary); } var img = new Image(); img.onload = function() { try { var canvas = document.createElement('canvas'); canvas.width = img.naturalWidth || img.width; canvas.height = img.naturalHeight || img.height; var ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0); buildHtml(canvas.toDataURL('image/png')); } catch (e) { buildHtml(null); } }; img.onerror = function() { buildHtml(null); }; img.src = 'assets/logo-transparente.png'; } function doRegisterPedido(clientData, cb) { var order = getCartOrder(); if (!order || !order.items.length) { if (cb) cb(true, clientData); return; } var refEl = document.getElementById('payment-reference'); var refVal = refEl ? (refEl.value || '').trim() : ''; if (!refVal) refVal = generatePaymentReference(); var cartItems = getCart(); var payload = { items: order.items.map(function(it, idx) { var cartIt = cartItems[idx] || {}; return { id: cartIt.id, name: it.name, quantity: it.quantity, unitPrice: it.unitPrice, subtotal: it.subtotal }; }), total: order.total, referencia_pago: refVal }; fetch('/api/cliente/pedidos.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload), credentials: 'same-origin' }).then(function(r) { return r.json(); }).then(function(res) { if (res.success) { try { sessionStorage.setItem(REGISTERED_CART_KEY, getCartFingerprint()); } catch (e) {} } if (cb) cb(res.success, clientData, res); }).catch(function() { if (cb) cb(false, clientData); }); } function saveOrderToAccount(cb) { fetch('/api/cliente/auth.php', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'action=check', credentials: 'same-origin' }).then(function(r) { return r.json(); }).then(function(authRes) { if (!authRes.success || !authRes.cliente) { if (cb) cb(null); return; } var clientData = { nombre: authRes.cliente.nombre || '', email: authRes.cliente.email || '', telefono: '' }; fetch('/api/cliente/perfil.php', { method: 'GET', credentials: 'same-origin' }) .then(function(r) { return r.json(); }) .then(function(profRes) { if (profRes.success && profRes.cliente && profRes.cliente.telefono) { clientData.telefono = profRes.cliente.telefono; } }) .catch(function() {}) .finally(function() { var order = getCartOrder(); if (!order || !order.items.length) { if (cb) cb(clientData); return; } var fp = getCartFingerprint(); var alreadyRegistered = false; try { alreadyRegistered = (sessionStorage.getItem(REGISTERED_CART_KEY) === fp); } catch (e) {} if (alreadyRegistered) { if (cb) cb(clientData); return; } doRegisterPedido(clientData, function(success) { if (cb) cb(clientData); }); }); }).catch(function() { if (cb) cb(null); }); } function showRegistroStatus(msg, isError) { var el = document.getElementById('compra-registro-status'); if (!el) return; el.innerHTML = msg || ''; el.style.display = msg ? 'block' : 'none'; el.style.background = isError ? '#fee2e2' : '#d1fae5'; el.style.color = isError ? '#991b1b' : '#065f46'; } var btnRegistrar = document.getElementById('btn-registrar-pedido'); if (btnRegistrar) { btnRegistrar.addEventListener('click', function() { if (!getCart().length) { showRegistroStatus('Tu carrito está vacío. Añade productos primero.', true); return; } var btn = this; btn.disabled = true; showRegistroStatus(''); fetch('/api/cliente/auth.php', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'action=check', credentials: 'same-origin' }).then(function(r) { return r.json(); }).then(function(authRes) { if (!authRes.success || !authRes.cliente) { showRegistroStatus('Debes iniciar sesión para registrar tu pedido. Iniciar sesión', true); btn.disabled = false; return; } var clientData = { nombre: authRes.cliente.nombre || '', email: authRes.cliente.email || '', telefono: '' }; fetch('/api/cliente/perfil.php', { method: 'GET', credentials: 'same-origin' }) .then(function(r) { return r.json(); }) .then(function(profRes) { if (profRes.success && profRes.cliente && profRes.cliente.telefono) { clientData.telefono = profRes.cliente.telefono; } }) .catch(function() {}) .finally(function() { doRegisterPedido(clientData, function(success, cd, res) { btn.disabled = false; if (success) { var ref = (res && res.referencia_pago) ? res.referencia_pago : (document.getElementById('payment-reference') && document.getElementById('payment-reference').value) || ''; showRegistroStatus('Pedido registrado correctamente. Referencia: ' + escapeHtml(ref) + '. Ya puedes descargar el comprobante y solicitar factura desde Mi cuenta.', false); } else { showRegistroStatus(escapeHtml((res && res.message) || 'Error al registrar el pedido. Intenta de nuevo.'), true); } }); }); }).catch(function() { showRegistroStatus('Error de conexión. Intenta de nuevo.', true); btn.disabled = false; }); }); } function showClipStatus(msg, isError) { var el = document.getElementById('compra-clip-status'); if (!el) return; el.innerHTML = msg || ''; el.style.display = msg ? 'block' : 'none'; el.style.background = isError ? '#fee2e2' : '#d1fae5'; el.style.color = isError ? '#991b1b' : '#065f46'; } var btnPagarClip = document.getElementById('btn-pagar-clip'); if (btnPagarClip) { btnPagarClip.addEventListener('click', function() { var order = getCartOrder(); if (!order || !order.items.length) { showClipStatus('Añade productos al carrito antes de pagar.', true); return; } if (order.aCotizar) { showClipStatus('El total está "a cotizar". No se puede generar link de pago con tarjeta.', true); return; } if (!CLIP_API_BASE) { showClipStatus('Pago con Clip no configurado. Indica la URL del backend en esta página (CLIP_API_BASE).', true); return; } var refEl = document.getElementById('payment-reference'); var refVal = refEl ? (refEl.value || '').trim() : ''; if (!refVal) refVal = generatePaymentReference(); var btn = this; btn.disabled = true; showClipStatus(''); var payload = { items: order.items.map(function(it) { return { name: it.name, quantity: it.quantity, unitPrice: it.unitPrice, subtotal: it.subtotal }; }), total: order.total, referencia_pago: refVal, success_url: window.location.origin + window.location.pathname + '?clip=ok&ref=' + encodeURIComponent(refVal), cancel_url: window.location.origin + window.location.pathname + '?clip=cancel' }; fetch(CLIP_API_BASE + '/api/clip/crear-link', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }).then(function(r) { return r.json(); }).then(function(res) { btn.disabled = false; if (res.success && res.payment_url) { window.location.href = res.payment_url; } else { showClipStatus(escapeHtml(res.message || 'No se pudo generar el link de pago.'), true); } }).catch(function(err) { btn.disabled = false; showClipStatus('Error de conexión con el servidor de pagos. Intenta de nuevo.', true); }); }); } document.getElementById('btn-cotizar-envio')?.addEventListener('click', function() { var form = document.getElementById('formEntrega'); var cp = (document.getElementById('entregaCP')?.value || '').replace(/\D/g, ''); var nombre = (document.getElementById('entregaNombre')?.value || '').trim(); var calle = (document.getElementById('entregaCalle')?.value || '').trim(); if (cp.length !== 5) { document.getElementById('envio-cotizacion-msg').textContent = 'Ingresa un código postal de 5 dígitos.'; document.getElementById('envio-cotizacion-msg').className = 'envio-cotizacion-msg error'; document.getElementById('envio-cotizacion-result').style.display = 'block'; return; } var order = getCartOrder(); var pesoEst = 8; if (order && order.items.length) { pesoEst = order.items.reduce(function(s, it) { return s + (it.quantity || 1) * 8; }, 0); pesoEst = Math.max(5, Math.min(100, pesoEst)); } var btn = this; btn.disabled = true; document.getElementById('envio-rates-list').innerHTML = ''; document.getElementById('envio-cotizacion-msg').textContent = 'Cotizando...'; document.getElementById('envio-cotizacion-msg').className = 'envio-cotizacion-msg'; document.getElementById('envio-cotizacion-result').style.display = 'block'; fetch('/api/cotizar-envio.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ cp_destino: cp, peso: pesoEst, ancho: 50, alto: 40, profundidad: 40 }) }).then(function(r) { return r.json(); }).then(function(res) { btn.disabled = false; var listEl = document.getElementById('envio-rates-list'); var msgEl = document.getElementById('envio-cotizacion-msg'); if (res.success && res.rates && res.rates.length) { msgEl.textContent = 'Selecciona una opción de envío:'; msgEl.className = 'envio-cotizacion-msg'; listEl.innerHTML = res.rates.map(function(rate) { return '
' + '' + escapeHtml(rate.carrier) + '' + '' + formatMoney(rate.price) + '
'; }).join(''); listEl.querySelectorAll('.envio-rate-item').forEach(function(el) { el.addEventListener('click', function() { listEl.querySelectorAll('.envio-rate-item').forEach(function(x) { x.classList.remove('selected'); }); el.classList.add('selected'); selectedEnvio = { rate: { carrier: el.dataset.carrier, price: parseFloat(el.dataset.price) }, direccion: { nombre: document.getElementById('entregaNombre')?.value || '', telefono: document.getElementById('entregaTelefono')?.value || '', calle: document.getElementById('entregaCalle')?.value || '', colonia: document.getElementById('entregaColonia')?.value || '', cp: document.getElementById('entregaCP')?.value || '', ciudad: document.getElementById('entregaCiudad')?.value || '', estado: document.getElementById('entregaEstado')?.value || '' } }; }); }); } else { msgEl.textContent = res.message || 'No se encontraron opciones de envío. Verifica el código postal.'; msgEl.className = 'envio-cotizacion-msg error'; } }).catch(function() { btn.disabled = false; document.getElementById('envio-cotizacion-msg').textContent = 'Error de conexión. Intenta de nuevo.'; document.getElementById('envio-cotizacion-msg').className = 'envio-cotizacion-msg error'; }); }); var btnDownload = document.getElementById('btn-download-pdf'); if (btnDownload) { btnDownload.addEventListener('click', function() { if (!getCart().length) return; var btn = this; btn.disabled = true; saveOrderToAccount(function(clientData) { downloadHtml(clientData || {}); btn.disabled = false; }); }); } function updateMailtoComprobante() { var order = getCartOrder(); var subject = 'Referenciador para pago o transferencia - BD Distribuidora'; var totalStr = order && order.aCotizar ? 'A cotizar' : (order ? formatMoney(order.total) : ''); var body = order && order.items.length ? 'Pedido (llantas/rines):\n' + order.items.map(function(it) { return it.name + ' x ' + it.quantity; }).join('\n') + '\n\nTotal: ' + totalStr + '\n\nAdjunto comprobante.\n\nMi nombre: ' : ''; var href = 'mailto:contacto@bddistribuidora.com?subject=' + encodeURIComponent(subject) + (body ? '&body=' + encodeURIComponent(body) : ''); var link = document.getElementById('mailto-comprobante'); if (link) link.setAttribute('href', href); } function updateCartFromUrl() { var id = getProductId(); var params = new URLSearchParams(window.location.search); var qty = Math.max(1, parseInt(params.get('qty'), 10) || 1); if (id && PRODUCTS_PRICING[id]) { addToCart(id, qty, PRODUCTS_PRICING[id].name); window.history.replaceState({}, '', 'compra.html'); } } initProductSelect(); updateCartFromUrl(); var btnAdd = document.getElementById('btn-add-to-cart'); if (btnAdd) { btnAdd.addEventListener('click', function() { var select = document.getElementById('product-select'); var qtyEl = document.getElementById('add-quantity'); var id = select ? select.value : ''; var qty = (qtyEl && parseInt(qtyEl.value, 10)) || 1; if (id) { addToCart(id, qty, (PRODUCTS_PRICING[id] && PRODUCTS_PRICING[id].name) || ''); renderCart(); if (select) select.value = ''; if (qtyEl) qtyEl.value = 1; } }); } renderCart(); window.addEventListener('bddistribuidora_products_ready', refreshCompraPricing); window.addEventListener('bddistribuidora_rines_ready', refreshCompraPricing); var urlParams = new URLSearchParams(window.location.search); if (urlParams.get('clip') === 'ok') { var refOk = urlParams.get('ref') || ''; var clipMsgEl = document.getElementById('compra-clip-status'); if (clipMsgEl) { clipMsgEl.innerHTML = 'Pago registrado. Clip procesará tu pago y te contactaremos. Referencia: ' + escapeHtml(refOk); clipMsgEl.style.display = 'block'; clipMsgEl.style.background = '#d1fae5'; clipMsgEl.style.color = '#065f46'; } } })();