https://www.bolsadecaracas.com/wp-content/themes/bvc/assets/js/productos-y-servicios.js?v=1790295810
1var car_productos = []; 2 3$(document).ready(function () { 4 var params = getParams(); 5 if (params.paymentID) { 6 crearReciboComprasPaypal( 7 params.subtotalCart, 8 params.ivaCart, 9 params.totalCart, 10 JSON.parse(params.productosComprados) 11 ); 12 } 13}); 14 15async function loadBasic() { 16 getMainCategories().then((result) => { 17 console.log(result); 18 }); 19} 20 21async function getMainCategories() { 22 return new Promise((resolve, reject) => { 23 let idParent = 1; 24 var containerMainCategories = document.getElementById( 25 'containerMainCategories' 26 ); 27 28 $('#containerMainCategories').html(` 29 <div class="row pb-4 d-flex justify-content-center"><div class="preloader"></div></div> 30 `); 31 32 $.post( 33 home + '/wp-admin/admin-ajax.php', 34 { action: 'getSubCategories', idParent: idParent }, 35 function (data) { 36 var categories = data.categorias; 37 38 //ELIMINAMOS LO QUE ESTE EN EL CONTENEDOR 39 while (containerMainCategories.firstChild) { 40 containerMainCategories.removeChild( 41 containerMainCategories.firstChild 42 ); 43 } 44 45 //ESCRIBIMOS LOS NUEVOS ELEMENTOS 46 var i = 0; 47 var classActive; 48 categories.forEach((category) => { 49 // if (category.ID == "124") { 50 51 if (i === 0) { 52 classActive = 'btn-pnPS'; 53 } else { 54 classActive = 'btn-pjPS'; 55 } 56 57 let html = `<a class="btn btn-primary btn-lg active ${classActive} ml-4 mr-3 text-uppercase mt-2" role="button" aria-pressed="true" data-id="${category.ID}" data-name="${category.TX_DESCRIPTION}" data-parent="${category.NU_PARENT}" onclick="changeCategory(${category.ID})"> 58 ${category.TX_DESCRIPTION} 59 </a>`; 60 61 containerMainCategories.insertAdjacentHTML('beforeend', html); 62 i++; 63 // } 64 }); 65 66 changeCategory(categories[0].ID); 67 resolve(true); 68 }, 69 'json' 70 ); 71 }); 72} 73 74function changeCategory(idParent) { 75 console.log(idParent); 76 let parent = document.querySelector(`[data-id="${idParent}"]`); 77 78 var nameParent = parent.dataset.name; 79 80 let mainCategories = document.querySelectorAll('[data-parent="1"]'); 81 82 mainCategories.forEach(function (cat, i) { 83 cat.removeAttribute('onclick'); 84 85 if (cat.dataset.id != idParent) { 86 cat.classList.add('d-none'); 87 } 88 }); 89 90 mainCategories.forEach(function (mainCategory, index) { 91 document 92 .querySelector(`[data-id="${mainCategory.dataset.id}"]`) 93 .classList.remove('btn-pnPS'); 94 document 95 .querySelector(`[data-id="${mainCategory.dataset.id}"]`) 96 .classList.remove('btn-pjPS'); 97 98 if (mainCategory.dataset.id == idParent) { 99 document 100 .querySelector(`[data-id="${idParent}"]`) 101 .classList.add('btn-pnPS'); 102 103 var containerCategories = document.getElementById('containerProducts'); 104 105 //ELIMINAMOS LO QUE ESTE EN EL CONTENEDOR 106 while (containerCategories.firstChild) { 107 containerCategories.removeChild(containerCategories.firstChild); 108 } 109 //setTimeout(function(){ 110 $.post( 111 home + '/wp-admin/admin-ajax.php', 112 { action: 'getSubCategories', idParent: idParent }, 113 function (data) { 114 let response = data.categorias; 115 116 //ESCRIBIMOS LOS NUEVOS ELEMENTOS 117 118 if (response.length === 0) { 119 let html = `No se encuentra información`; 120 121 //containerCategories.insertAdjacentHTML("beforeend", html); 122 } else { 123 var html = ''; 124 response.forEach((category) => { 125 if (category.NU_STATUS == '1') { 126 html += `<div class="col-sm-3 col-6"> 127 <div class="row"> 128 <div class="col-sm-12 text-center"> 129 <img class="productos-content-img w-75" src="${home}/wp-content/uploads/productos/categoria/1.svg" alt="Diario de la bolsa"> 130 <div class="bold text-uppercase text-center pt-0 pt-md-4"> 131 ${category.TX_DESCRIPTION} 132 </div> 133 <button class="btn btn-success btn-producto text-uppercase px-5 px-md-5 mt-4" data-id="${category.ID}" data-filtro="${category.NU_PARENT}" data-parent="${nameParent}" data-name="${category.TX_DESCRIPTION}" onclick="getProductsByCategory(this)">ver</button> 134 </div> 135 </div> 136 </div>`; 137 } 138 }); 139 containerCategories.insertAdjacentHTML('beforeend', html); 140 } 141 }, 142 'json' 143 ); 144 //}, 2500); 145 } else { 146 document 147 .querySelector(`[data-id="${mainCategory.dataset.id}"]`) 148 .classList.add('btn-pjPS'); 149 } 150 }); 151
152 mainCategories.forEach(function (cat, i) { 153 if (cat.dataset.id != idParent) { 154 cat.classList.remove('d-none'); 155 } 156 157 cat.setAttribute('onclick', 'changeCategory(' + cat.dataset.id + ')'); 158 }); 159} 160 161function getProductsByCategory(parent) { 162 let cartBtnRight = document.getElementById('viewCart'); 163 cartBtnRight.setAttribute('disabled', ''); 164 165 document.getElementById('detalleProducto').classList.remove('d-none'); 166 document.getElementById('inicioProd').classList.add('d-none'); 167 168 $('#prodDetalle #prodTitle').html(''); 169 $('#prodDetalle #prodDescription').html(''); 170 $('#prodDetalle #containerDetalles').html(''); 171 172 // let dataAPI = document.querySelector('[data-api]').dataset.api; 173 174 // document.getElementById("image-category").src = `${dataAPI}upload/productos/categoria/${parent.dataset.id}.png`; 175 176 let headerContainer = document.getElementById('headerDetalle'); 177 178 //ELIMINAMOS LO QUE ESTE EN EL HEADER 179 while (headerContainer.firstChild) { 180 headerContainer.removeChild(headerContainer.firstChild); 181 } 182 183 let nameParent = parent.dataset.name; 184 185 let nameGrand = parent.dataset.parent; 186 187 let idParent = parent.dataset.id; 188 189 let header = `<a class="btn btn-primary btn-lg active btn-pjPS ml-4 mr-2 text-uppercase mt-2" role="button" aria-pressed="true" id="btTipoCategoria" onclick="showCategory()">${nameGrand}</a> > 190 <a class="btn btn-primary btn-lg active btn-pnPS ml-2 mr-3 text-uppercase mt-2" role="button" aria-pressed="true" id="btTipoProducto">${nameParent}</a>`; 191 192 headerContainer.insertAdjacentHTML('beforeend', header); 193 194 let titleContainer = document.getElementById('titleDetalle'); 195 196 //ELIMINAMOS LO QUE ESTE EN EL TITULO 197 while (titleContainer.firstChild) { 198 titleContainer.removeChild(titleContainer.firstChild); 199 } 200 201 // AGREGAMOS EL TITULO DE LA CETGORIA 202 titleContainer.insertAdjacentHTML('beforeend', nameParent); 203 204 // BUSCAMOS LOS PRODUCTOS DE LA CATEGORIA 205 206 $.post( 207 home + '/wp-admin/admin-ajax.php', 208 { action: 'getProducts', idParent: idParent }, 209 function (data) { 210 let productos = JSON.parse(data.productos); 211 212 let categorias = JSON.parse(data.categorias); 213 214 productos = productos.productos; 215 216 categorias = categorias.categorias; 217 218 let productsContainer = document.getElementById('productsContainer'); 219 220 //ELIMINAMOS LO QUE ESTE EN EL CONTENEDOR 221 while (productsContainer.firstChild) { 222 productsContainer.removeChild(productsContainer.firstChild); 223 } 224 225 // IMPRIMIMOS LOS PRODUCTOS 226 productos.forEach((producto) => { 227 if (producto.NU_STATUS === '1') { 228 let html = `<div><a class="text-center leftmenu" data-target="producto" data-id="${producto.ID}" onclick="getProduct(this)"><i class="fa fa-arrow-right icon mr-1 mr-md-4" aria-hidden="true"></i>${producto.TX_TITULO}</a></div>`; 229 230 productsContainer.insertAdjacentHTML('beforeend', html); 231 } 232 }); 233 234 categorias.forEach((categoria) => { 235 if (categoria.NU_STATUS === '1') { 236 let html = `<div><a class="text-center leftmenu" data-target="categoria" data-title="${categoria.TX_DESCRIPTION}" data-id="${categoria.ID}" onclick="getProduct(this)"><i class="fa fa-arrow-right icon mr-1 mr-md-4" aria-hidden="true"></i>${categoria.TX_DESCRIPTION}</a></div>`; 237 238 productsContainer.insertAdjacentHTML('beforeend', html); 239 } 240 }); 241 }, 242 'json' 243 ); 244} 245 246function showCategory() { 247 $('#detalleProducto').addClass('d-none'); 248 $('#inicioProd').removeClass('d-none'); 249} 250 251function getProduct(element) { 252 let id = element.dataset.id; 253 254 let target = element.dataset.target; 255 256 let cartBtnRight = document.getElementById('viewCart'); 257 //cartBtnRight.setAttribute("disabled", "") 258 let productLink = document.querySelectorAll('#productsContainer a'); 259 260 productLink.forEach((alink) => { 261 alink.removeAttribute('onclick'); 262 }); 263 264 preload = document.getElementById('carga'); 265 let html = `<div class="preloader"></div>`; 266 267 preload.insertAdjacentHTML('beforeend', html); 268 269 $.post( 270 home + '/wp-admin/admin-ajax.php', 271 { action: 'getProduct', idParent: id, target: target }, 272 function (data) { 273 let productoTitle = document.getElementById('prodTitle'); 274 275 //ELIMINAMOS LO QUE ESTE EN EL CONTENEDOR 276 while (productoTitle.firstChild) { 277 productoTitle.removeChild(productoTitle.firstChild); 278 } 279 280 let productoDescription = document.getElementById('prodDescription'); 281 282 //ELIMINAMOS LO QUE ESTE EN EL CONTENEDOR 283 while (productoDescription.firstChild) { 284 productoDescription.removeChild(productoDescription.firstChild); 285 } 286 287 let containerDetalles = document.getElementById('containerDetalles'); 288 289 //ELIMINAMOS LO QUE ESTE EN EL CONTENEDOR de detalles 290 while (containerDetalles.firstChild) { 291 containerDetalles.removeChild(containerDetalles.firstChild); 292 } 293 294 let html = `<table class="table table-hover"> 295 <thead id="thead-detalleProd"> 296 <tr class="text-center"> 297 <th scope="col" class="text-center text-uppercase text-gray bold"> 298 nombre 299 </th> 300 <th scope="col" class="text-center text-uppercase text-gray bold"> 301 monto 302 </th> 303 <th scope="col" class="text-center text-uppercase text-gray bold"> 304 agregar al carrito 305 </th> 306 </tr> 307 </thead> 308 <tbody id="tbody-detalleProd" class="text-center"> 309 310 </tbody> 311 </table>`; 312 313 containerDetalles.insertAdjacentHTML('beforeend', html); 314 315 let tbodyDetalles = document.getElementById('tbody-detalleProd'); 316 317 if (target === 'producto') { 318 // SI ES UN PRODUCTO 319 320 if (data.hasOwnProperty('producto')) { 321 while (tbodyDetalles.firstChild) { 322 tbodyDetalles.removeChild(tbodyDetalles.firstChild); 323 } 324 let producto = data.producto[0]; 325 productoTitle.insertAdjacentHTML('beforeend', producto.TX_TITULO); 326 productoDescription.insertAdjacentHTML( 327 'beforeend', 328 producto.TX_DESCRIPTION 329 ); 330 productoDescription.insertAdjacentHTML( 331 'beforeend', 332 '<p class="mt-5">A continuación la información del producto:</p>' 333 ); 334 let myHeaders = new Headers(); 335 let dataPost = new FormData(); 336 dataPost.append('action', 'getPrecio'); 337 dataPost.append('id', producto.ID); 338 fetch(`${home}/wp-admin/admin-ajax.php`, { 339 method: 'POST', 340 body: dataPost, 341 credentials: 'same-origin', 342 headers: myHeaders, 343 }) 344 .then((res) => res.json()) 345 .catch((error) => console.error('Error:', error)) 346 .then((response) => { 347 let precios = response.precio; 348 var preciosHTML = `<select class="form-control" line="338" id="precio-${producto.ID}" data-id="precio-${producto.ID}">`; 349 precios.forEach((precio) => { 350 let myHeaders = new Headers(); 351 let dataPost = new FormData(); 352 dataPost.append('action', 'getPeriodoDePago'); 353 dataPost.append('id', precio.NU_PERIODO_PAGO_ID); 354 fetch(`${home}/wp-admin/admin-ajax.php`, { 355 method: 'POST', 356 body: dataPost, 357 credentials: 'same-origin', 358 headers: myHeaders, 359 }) 360 .then((res) => res.json()) 361 .catch((error) => console.error('Error:', error)) 362 .then((response) => { 363 let periodo_pago = ''; 364 365 if (precio.NU_ACTIVO == '1') { 366 let periodo_pago = response.periodo_pago[0]; 367 let PRECIO = FN(precio.NU_PRECIO); 368 precios += `<option class="hidePrecio" id="${precio.NU_ACTIVO}" data-precio="${precio.NU_PRECIO}" data-moneda="${precio.TX_MONEDA}" data-periodo="${periodo_pago.TX_DESCRIPTION}" value="${precio.ID}">${PRECIO} ${precio.TX_MONEDA} - ${periodo_pago.TX_DESCRIPTION}</option>`; 369 370 jQuery('#precio-' + producto.ID).html(precios); 371 } 372 }); 373 }); 374 375 preciosHTML += `</select>`; 376 let html = `<tr> 377 <td>${producto.TX_TITULO}</td> 378 <td>${preciosHTML}</td> 379 <td> 380 <!-- img class="productos-detalle-img text-center pointer" src="${theme}/assets/img/productos/carrito_compras_1.svg" alt="carrito compra" onclick="carroAdd(${producto.ID}, this)" --> 381 <a href="javascript:;" onclick="carroAdd(${producto.ID}, this)" id="producto-add-${producto.ID}"> 382 <i class="fas fa-2x fa-cart-plus"></i> 383 </a> 384 <a href="javascript:;" class="sr-only" id="producto-check-${producto.ID}"> 385 <i class="fas fa-2x fa-check-circle"></i> 386 </a> 387 </td> 388 </tr>`; 389 tbodyDetalles.insertAdjacentHTML('beforeend', html); 390 while (preload.firstChild) { 391 preload.removeChild(preload.firstChild); 392 } 393 productLink.forEach((alink) => { 394 alink.setAttribute('onclick', 'getProduct(this)'); 395 }); 396 }); 397 } else if (data.hasOwnProperty('productos')) { 398 // SI ES UN PLAN 399 let plan = data.plan; 400 401 plan = JSON.parse(plan); 402 403 plan = plan.producto[0]; 404 405 let plan_id = plan.ID; 406 407 let myHeaders = new Headers(); 408 409 let dataPost = new FormData(); 410 411 dataPost.append('action', 'getPrecio'); 412 413 dataPost.append('id', plan_id); 414 415 fetch(`${home}/wp-admin/admin-ajax.php`, { 416 method: 'POST', 417 body: dataPost, 418 credentials: 'same-origin', 419 headers: myHeaders, 420 }) 421 .then((res) => res.json()) 422 .catch((error) => console.error('Error:', error)) 423 .then((response) => { 424 let precios = response.precio; 425 426 var preciosHTML = `<select class="form-control" line="411" id="precio-${plan_id}" data-id="precio-${plan_id}">`; 427 428 precios.forEach((precio) => { 429 let myHeaders = new Headers(); 430 431 let dataPost = new FormData(); 432 433 dataPost.append('action', 'getPeriodoDePago'); 434 435 dataPost.append('id', precio.NU_PERIODO_PAGO_ID); 436 437 fetch(`${home}/wp-admin/admin-ajax.php`, { 438 method: 'POST', 439 body: dataPost, 440 credentials: 'same-origin', 441 headers: myHeaders, 442 }) 443 .then((res) => res.json()) 444 .catch((error) => console.error('Error:', error)) 445 .then((response) => { 446 let periodo_pago = response.periodo_pago[0]; 447 let PRECIO = FN(precio.NU_PRECIO); 448 precios += `<option data-precio="${precio.NU_PRECIO}" data-moneda="${precio.TX_MONEDA}" data-periodo="${periodo_pago.TX_DESCRIPTION}" value="${precio.ID}">${PRECIO} ${precio.TX_MONEDA} - ${periodo_pago.TX_DESCRIPTION}</option>`; 449 jQuery('#precio-' + plan_id).html(precios); 450 }); 451 }); 452 453 preciosHTML += `</select>`; 454 455 let html = `<tr> 456 <td>${plan.TX_TITULO}</td> 457 <td>${preciosHTML}</td> 458 <td> 459 <!-- img class="productos-detalle-img text-center pointer" src="${theme}/assets/img/productos/carrito_compras_1.svg" alt="carrito compra" onclick="carroAdd(${plan.ID}, this)" --> 460 <a href="javascript:;" onclick="carroAdd(${plan.ID}, this)" id="producto-add-${plan.ID}"> 461 <i class="fas fa-2x fa-cart-plus"></i> 462 </a> 463 <a href="javascript:;" class="sr-only" id="producto-check-${plan.ID}"> 464 <i class="fas fa-2x fa-check-circle"></i> 465 </a> 466 </td> 467 </tr>`; 468 469 tbodyDetalles.insertAdjacentHTML('beforeend', html); 470 471 while (preload.firstChild) { 472 preload.removeChild(preload.firstChild); 473 } 474 475 productLink.forEach((alink) => { 476 alink.setAttribute('onclick', 'getProduct(this)'); 477 }); 478 //cartBtnRight.removeAttribute("disabled"); 479 }); 480 } 481 } else if (target === 'categoria') { 482 // SI ES UNA CATEGORIA 483 484 let productos = data.productos; 485 productoTitle.insertAdjacentHTML('beforeend', element.dataset.title); 486 productoDescription.insertAdjacentHTML( 487 'beforeend', 488 'Productos de la categoria' 489 ); 490 productoDescription.insertAdjacentHTML( 491 'beforeend', 492 '<p class="mt-5">A continuación la lista de productos disponibles:</p>' 493 ); 494 // LIMPIAMOS EL CONTENEDOR 495 while (tbodyDetalles.firstChild) { 496 tbodyDetalles.removeChild(tbodyDetalles.firstChild); 497 } 498 productos.forEach((producto) => { 499 let myHeaders = new Headers(); 500 let dataPost = new FormData(); 501 dataPost.append('action', 'getPrecio'); 502 dataPost.append('id', producto.ID); 503 fetch(`${home}/wp-admin/admin-ajax.php`, { 504 method: 'POST', 505 body: dataPost, 506 credentials: 'same-origin', 507 headers: myHeaders, 508 }) 509 .then((res) => res.json()) 510 .catch((error) => console.error('Error:', error)) 511 .then((response) => { 512 let precios = response.precio; 513 var preciosHTML = `<select class="form-control" line="503" id="precio-${producto.ID}" data-id="precio-${producto.ID}">>`; 514 preciosHTML += `</select>`; 515 let html = `<tr> 516 <td>${producto.TX_TITULO}</td> 517 <td>${preciosHTML}</td> 518 <td><img class="productos-detalle-img text-center pointer" src="${theme}/assets/img/productos/carrito_compras_1.svg" alt="carrito compra" onclick="add_product(${producto.ID}, '${producto.TX_TITULO}', this)"></td> 519 </tr>`; 520 tbodyDetalles.insertAdjacentHTML('beforeend', html); 521 522 var objPrecio = jQuery('[data-id="precio-' + producto.ID + '"]'); 523 precios.forEach((precio) => { 524 let myHeaders = new Headers(); 525 526 let dataPost = new FormData(); 527 528 dataPost.append('action', 'getPeriodoDePago'); 529 530 dataPost.append('id', precio.NU_PERIODO_PAGO_ID); 531 532 fetch(`${home}/wp-admin/admin-ajax.php`, { 533 method: 'POST', 534 body: dataPost, 535 credentials: 'same-origin', 536 headers: myHeaders, 537 }) 538 .then((res) => res.json()) 539 .catch((error) => console.error('Error:', error)) 540 .then((response) => { 541 let periodo_pago = response.periodo_pago[0]; 542 let PRECIO = FN(precio.NU_PRECIO); 543 precios += `<option data-precio="${precio.NU_PRECIO}" data-moneda="${precio.TX_MONEDA}" data-periodo="${periodo_pago.TX_DESCRIPTION}" value="${precio.ID}">${PRECIO} ${precio.TX_MONEDA} - ${periodo_pago.TX_DESCRIPTION}</option>`; 544 545 // let container = document.getElementById("precios"); 546 // container.insertAdjacentHTML("beforeend", precios); 547 objPrecio.html(precios); 548 }); 549 }); 550 551 while (preload.firstChild) { 552 preload.removeChild(preload.firstChild); 553 } 554 productLink.forEach((alink) => { 555 alink.setAttribute('onclick', 'getProduct(this)'); 556 }); 557 }); 558 }); 559 } 560 }, 561 'json' 562 ); 563} 564 565function getPrecio(id) { 566 $.post( 567 home + '/wp-admin/admin-ajax.php', 568 { action: 'getPrecio', id: id }, 569 function (data) { 570 localStorage.setItem('precio-' + id, JSON.stringify(data)); 571 }, 572 'json' 573 ); 574} 575 576function getPeriodoDePago(id) { 577 $.post( 578 home + '/wp-admin/admin-ajax.php', 579 { action: 'getPeriodoDePago', id: id }, 580 function (data) { 581 localStorage.setItem('periodo-' + id, JSON.stringify(data)); 582 }, 583 'json' 584 ); 585} 586 587function add_product(id, descrip
587cion, selector) { 588 selector.removeAttribute('onclick'); 589 590 let url = home + '/wp-admin/admin-ajax.php'; 591 592 let data = new FormData(); 593 594 data.append('action', 'validarToken'); 595 596 let headers = new Headers(); 597 598 fetch(url, { 599 method: 'POST', 600 body: data, 601 headers: headers, 602 }) 603 .then((res) => res.json()) 604 .catch((error) => console.error('Error:', error)) 605 .then((response) => { 606 let usuario = response.response; 607 608 if (usuario.length === 0) { 609 alert('Debe iniciar sesión para adquirir productos'); 610 selector.setAttribute( 611 'onclick', 612 'add_product(' + id + ", '" + descripcion + "', this)" 613 ); 614 } else { 615 let preload = document.getElementById('carga'); 616 617 let html = `<div class="preloader"></div>`; 618 619 preload.insertAdjacentHTML('beforeend', html); 620 621 let productos = JSON.parse(document.getElementById('productos').value); 622 let pass = true; 623 624 productos.forEach((producto) => { 625 if (producto.id === id) { 626 alert('Este producto ya fue agregado'); 627 pass = false; 628 while (preload.firstChild) { 629 preload.removeChild(preload.firstChild); 630 } 631 } 632 }); 633 634 if (pass) { 635 let url = home + '/wp-admin/admin-ajax.php'; 636 637 let headers = new Headers(); 638 639 let data = new FormData(); 640 641 data.append('action', 'insertCarrito'); 642 643 data.append('id_producto', id); 644 645 data.append('id_usuario', usuario[0].ICLIENTE); 646 647 let producto = document.querySelector(`[data-id=precio-${id}]`); 648 649 let producto_seleccionado = producto.options.item( 650 producto.selectedIndex 651 ); 652 653 data.append('precio', producto_seleccionado.dataset.precio); 654 data.append('moneda', producto_seleccionado.dataset.moneda); 655 data.append('periodo', producto_seleccionado.dataset.periodo); 656 657 fetch(url, { 658 method: 'POST', 659 body: data, 660 headers: headers, 661 }) 662 .then((res) => res.json()) 663 .catch((error) => console.error('Error:', error)) 664 .then((response) => { 665 productos.push({ 666 id: id, 667 descripcion: descripcion, 668 precio: producto_seleccionado.dataset.precio, 669 periodo: producto_seleccionado.dataset.periodo, 670 moneda: producto_seleccionado.dataset.moneda, 671 }); 672 673 document.getElementById('productos').value = 674 JSON.stringify(productos); 675 //alert('producto Agregado al Carro'); 676 $('#Continuar1').attr('disabled', false); 677 678 while (preload.firstChild) { 679 preload.removeChild(preload.firstChild); 680 } 681 }); 682 } 683 684 selector.setAttribute( 685 'onclick', 686 'add_product(' + id + ", '" + descripcion + "', this)" 687 ); 688 } 689 }); 690} 691 692function seleccionar_todos(seleccion) { 693 let url = document.querySelector('[data-image]').dataset.image; 694 695 let productos_seleccionados = document.querySelectorAll('[data-producto]'); 696 697 if (seleccion.dataset.select === 'unselected') { 698 productos_seleccionados.forEach((producto) => { 699 $('#' + producto.id).attr('src', `${url}/seleccion.svg`); 700 $('#' + producto.id).data('select', 'selected'); 701 }); 702 703 seleccion.src = `${url}/seleccion.svg`; 704 705 seleccion.dataset.select = 'selected'; 706 } else if (seleccion.dataset.select === 'selected') { 707 productos_seleccionados.forEach((producto) => { 708 $('#' + producto.id).attr('src', `${url}/deseleccionar.svg`); 709 $('#' + producto.id).data('select', 'unselected'); 710 }); 711 712 seleccion.src = `${url}/deseleccionar.svg`; 713 714 seleccion.dataset.select = 'unselected'; 715 } 716} 717 718function eliminar_producto(id, evento) { 719 let url = home + '/wp-admin/admin-ajax.php'; 720 721 let data = new FormData(); 722 723 data.append('action', 'validarToken'); 724 725 let headers = new Headers(); 726 727 fetch(url, { 728 method: 'POST', 729 body: data, 730 headers: headers, 731 }) 732 .then((res) => res.json()) 733 .catch((error) => console.error('Error:', error)) 734 .then((data) => { 735 if (data.response.length !== 0) { 736 let usuario = data.response[0]; 737 738 let user_id = usuario.ICLIENTE; 739 740 let body = new FormData(); 741 742 body.append('action', 'eliminarCarrito'); 743
744 body.append('user_id', user_id); 745 746 body.append('producto_id', id); 747 748 fetch(url, { 749 method: 'POST', 750 body: body, 751 headers: headers, 752 }) 753 .then((res) => res.json()) 754 .catch((error) => console.error('Error:', error)) 755 .then((data) => { 756 if (data.out === '1') { 757 if (evento == 1) { 758 //alert("El producto se elimino con exito"); 759 } 760 $('div#productoCarro-' + id).remove(); 761 var productos = JSON.parse( 762 document.getElementById('productos').value 763 ); 764 var productosNew = []; 765 jQuery.each(productos, function (i, val) { 766 if (val.id != id) { 767 productosNew.push({ 768 id: val.id, 769 descripcion: val.descripcion, 770 precio: val.precio, 771 periodo: val.periodo, 772 moneda: val.moneda, 773 }); 774 } 775 }); 776 document.getElementById('productos').value = 777 JSON.stringify(productosNew); 778 779 var cantproductos = productos.length - 1; 780 if (cantproductos == 0) { 781 $('#Continuar1').attr('disabled', true); 782 } 783 } else { 784 alert('Ha ocurrido un error'); 785 } 786 }); 787 } 788 }); 789} 790 791function paso_dos() { 792 let productos = JSON.parse(document.getElementById('productos').value); 793 var selects = false; 794 $('.checkProductos').each(function () { 795 var id = $(this).data('producto'); 796 var select = $(this).data('select'); 797 if (select == 'selected') { 798 selects = true; 799 } 800 }); 801 802 if (!selects) { 803 alert('Debe seleccionar al menos un producto'); 804 } else if (document.getElementById('monedasSelect').value == '0') { 805 alert('Debe seleccionar una moneda de pago'); 806 } else { 807 $('#cartModal2').modal('show'); 808 809 $('#cartModal').modal('hide'); 810 811 let total = 0; 812 let cantProductos = 0; 813 let productosComprados = []; 814 815 var Moneda = document.getElementById('monedasSelect').value; 816 var simbolo = 'BSS'; 817 if (Moneda == 'Dolar') { 818 simbolo = '$'; 819 } 820 821 var recibo_productos = ''; 822 productos.forEach((producto) => { 823 $('.checkProductos').each(function () { 824 var id = $(this).data('producto'); 825 var select = $(this).data('select'); 826 if (select == 'selected' && producto.id == id) { 827 total += parseFloat(producto.precio); 828 cantProductos++; 829 productosComprados.push(producto.id); 830 831 let item = car_productos.filter((v) => { 832 return v.id == producto.id; 833 }); 834 if (item == undefined || item.length == 0) { 835 car_productos.push({ 836 id: producto.id, 837 descripcion: producto.descripcion, 838 moneda: producto.moneda, 839 periodo: producto.periodo, 840 precio: producto.precio, 841 }); 842 localStorage.setItem( 843 'Y5yCZuOMTXJpYVBQE', 844 JSON.stringify(car_productos) 845 ); 846 } 847 848 recibo_productos = 849 recibo_productos + 850 '<div class="row text-gray"><div class="col-8">' + 851 producto.descripcion + 852 '</div><div class="col-4 text-right"> ' + 853 producto.precio + 854 ' ' + 855 simbolo + 856 '</div></div>'; 857 } 858 }); 859 }); 860 jQuery('#recibo-productos').html(recibo_productos); 861 862 document.getElementById('precio-total').innerText = `${total} ${simbolo}`; 863 864 let iva = total * 0.12; 865 866 let total_pagar = total + iva; 867 868 document.getElementById('iva').innerText = `${iva} ${simbolo}`; 869 document.getElementById( 870 'total-pagar' 871 ).innerText = `${total_pagar} ${simbolo}`; 872 document.getElementById('subtotalCart').value = total; 873 document.getElementById('ivaCart').value = iva; 874 document.getElementById('totalCart').value = total_pagar; 875 876 // Descripcion del recibo 877 // ********************************** 878 document.getElementById( 879 'recibo-subtotalCart' 880 ).innerText = `${total} ${simbolo}`; 881 document.getElementById('recibo-iva').innerText = `${iva} ${simbolo}`; 882 document.getElementById( 883 'recibo-total-pagar' 884 ).innerText = `${total_pagar} ${simbolo}`; 885 886 let description = document.getElementById('description-compra'); 887 888 // Borramos la descripcion 889 890 while (description.firstChild) { 891 description.removeChild(description.firstChild); 892 } 893 894 let html = `Usted tiene <strong>${cantProductos} producto(s)</strong> seleccionado para esta compra`; 895 896 description.insertAdjacentHTML('beforeend', html); 897 898 let metodos = document.querySelectorAll('[data-metodo]'); 899 900 metodos.forEach((metodo) => { 901 metodo.addEventListener('click', cambiar_metodo_pago, false); 902 }); 903 904 document.getElementById('productosComprados').value = 905 JSON.stringify(productosComprados); 906 } 907 908 function cambiar_metodo_pago(metodo) { 909 let url = document.querySelector('[data-image]').dataset.image; 910 911 let metodo_seleccionado = metodo.target; 912 913 let metodos = document.querySelectorAll('[data-metodo]'); 914 915 metodos.forEach((metodo) => { 916 metodo.src = `${url}/deseleccionar.svg`; 917 918 metodo.dataset.metodoSelecionado = 'false'; 919 }); 920 921 metodo_seleccionado.src = `${url}/seleccion.svg`; 922 923 metodo_seleccionado.dataset.metodoSelecionado = 'true'; 924 925 if (metodo_seleccionado.dataset.metodo === 'paypal') { 926 // ELIMINAMOS LOS D-NONE 927 document.getElementById('continuar-metodo').classList.remove('d-none'); 928 document.getElementById('paypal-btn').classList.remove('d-none'); 929 930 // AGREGAMOS EL D-NONE AL BOTON 931 document.getElementById('continuar-metodo').classList.add('d-none'); 932 } else { 933 // ELIMINAMOS LOS D-NONE 934 document.getElementById('continuar-metodo').classList.remove('d-none'); 935 document.getElementById('paypal-btn').classList.remove('d-none'); 936 937 // AGREGAMOS EL D-NONE AL BOTON 938 document.getElementById('paypal-btn').classList.add('d-none'); 939 } 940 } 941} 942 943function paso_tres() { 944 let opcion = document.querySelector('[data-metodo-selecionado="true"]'); 945 946 $('#recibo-notificacion').html(''); 947 $('#recibo-notificacion').addClass('sr-only'); 948 if (opcion) { 949 if ( 950 opcion.dataset.metodo === 'tarjeta-credito' || 951 opcion.dataset.metodo === 'tarjeta-debito' 952 ) { 953 $('#cartModal2').modal('hide');
954 $('#modal-tarjeta-credito').modal('show'); 955 $('#recibo-metodo_pago').html('Tarjeta Debito / Credito'); 956 } 957 958 if (opcion.dataset.metodo === 'deposito-transferencia') { 959 $('#cartModal2').modal('hide'); 960 $('#modal-deposito-transferencia').modal('show'); 961 $('#recibo-metodo_pago').html('Deposito / Transferencia'); 962 $('#recibo-notificacion').html( 963 'Para completar el proceso de pago debe realizar la transferencia o deposito y proceder a notificar el pago' 964 ); 965 $('#recibo-notificacion').removeClass('sr-only'); 966 } 967 } else { 968 alert('Debe escojer un metodo de pago'); 969 } 970} 971 972function finalizar_compra(id) { 973 if (id == 'modal-deposito-transferencia') { 974 /* if (id == "modal-validar-deposito-transferencia") { 975 $('#finDeposit').attr('disabled', ''); 976 if ( 977 $("#bancoOrigen").val() == "" || 978 $("#bancoDestino").val() == "" || 979 $("#numeroDeReferencia").val() == "" || 980 $("#numeroDeRecibo").val() == "" || 981 $("#montoPagado").val() == "" || 982 $("#fechaDePago").val() == "" 983 ) { 984 alert("Debe agregar todos los datos de la transferencia o deposito"); 985 $('#finDeposit').removeAttr('disabled'); 986 return false; 987 } else { 988 crearReciboCompras(id,0); 989 } */ 990 991 crearReciboCompras(id, 0); 992 } else if (id == 'modal-tarjeta-credito') { 993 $('#finCredit').attr('disabled', ''); 994 995 if ( 996 $('#nombreTitular').val() == '' || 997 $('#nroTarjeta1').val() == '' || 998 $('#nroTarjeta2').val() == '' || 999 $('#nroTarjeta3').val() == '' || 1000 $('#nroTarjeta4').val() == '' || 1001 $('#diaVencimiento').val() == '' || 1002 $('#mesVencimiento').val() == '' || 1003 $('#anioVencimiento').val() == '' || 1004 $('#ccv').val() == '' || 1005 $('#tipoTarjeta').val() == '' 1006 ) { 1007 alert('Debe agregar todos los datos de la Tarjeta'); 1008 $('#finCredit').removeAttr('disabled'); 1009 return false; 1010 } else { 1011 crearReciboCompras(id, 1); 1012 } 1013 } else { 1014 $(`#${id}`).modal('hide'); 1015 $('#modal-fin').modal('show'); 1016 1017 $('#finDeposit').removeAttr('disabled'); 1018 $('#finCredit').removeAttr('disabled'); 1019 } 1020} 1021 1022function crearReciboCompras(id, status) { 1023 var datos = { 1024 P_NU_SUBTOTAL: $('#subtotalCart').val(), 1025 P_NU_IMPUESTOS: $('#ivaCart').val(), 1026 P_NU_TOTAL: $('#totalCart').val(), 1027 P_NU_ESTATUS: status, 1028 id: id, 1029 }; 1030 let productosComprados = JSON.parse( 1031 document.getElementById('productosComprados').value 1032 ); 1033 //saveRecibo(datos) 1034} 1035 1036function crearReciboComprasPaypal( 1037 subtotalCart, 1038 ivaCart, 1039 totalCart, 1040 productosComprados 1041) { 1042 var datos = { 1043 P_NU_SUBTOTAL: subtotalCart, 1044 P_NU_IMPUESTOS: ivaCart, 1045 P_NU_TOTAL: totalCart, 1046 P_NU_ESTATUS: 1, 1047 }; 1048 //saveRecibo( datos ); 1049} 1050 1051function salirCarro() { 1052 window.location.href = home; 1053} 1054 1055/* 1056 ***************************** 1057 Carrito 1058 ***************************** 1059 */ 1060 1061getCarrito(); 1062 1063function show_cart() { 1064 mostrarProductos(); 1065} 1066 1067function getCarrito() { 1068 let url = home + '/wp-admin/admin-ajax.php'; 1069 1070 let data = new FormData(); 1071 1072 data.append('action', 'validarToken'); 1073 1074 let headers = new Headers(); 1075 1076 fetch(url, { 1077 method: 'POST', 1078 body: data, 1079 headers: headers, 1080 }) 1081 .then((res) => res.json()) 1082 .catch((error) => console.error('Error:', error)) 1083 .then((data) => { 1084 if (data.response.length !== 0) { 1085 checkUser = true; 1086 let usuario = data.response[0]; 1087 let user_id = usuario.ICLIENTE; 1088 let body = new FormData(); 1089 body.append('action', 'getCarrito'); 1090 body.append('user_id', user_id); 1091 fetch(url, { 1092 method: 'POST', 1093 body: body, 1094 headers: headers, 1095 }) 1096 .then((res) => res.json()) 1097 .catch((error) => console.error('Error:', error)) 1098 .then((data) => { 1099 /*let productos = JSON.parse( 1100 document.getElementById("productos").value 1101 );*/ 1102 1103 let productos = []; 1104 1105 data.forEach((producto) => { 1106 productos.push({ 1107 id: producto.ID, 1108 descripcion: producto.TX_TITULO, 1109 precio: producto.PRECIO, 1110 periodo: producto.PERIODO, 1111 moneda: producto.MONEDA, 1112 }); 1113 }); 1114 1115 document.getElementById('productos').value = 1116 JSON.stringify(productos); 1117 }); 1118 } else { 1119 checkUser = false;
1120 } 1121 }); 1122} 1123 1124function mostrarProductos() { 1125 if (checkUser) { 1126 let productos = JSON.parse(document.getElementById('productos').value); 1127 1128 let listaProductos = document.getElementById('listaProductos'); 1129 1130 while (listaProductos.firstChild) { 1131 listaProductos.removeChild(listaProductos.firstChild); 1132 } 1133 1134 let urlImage = document.querySelector('[data-image]').dataset.image; 1135 1136 let monedas = []; 1137 1138 for (let i = 0; i < productos.length; i++) { 1139 monedas.push(productos[i].moneda); 1140 } 1141 1142 let monedas_filtradas = monedas.filter(function ( 1143 valor, 1144 indiceActual, 1145 arreglo 1146 ) { 1147 let indiceAlBuscar = arreglo.indexOf(valor); 1148 if (indiceActual === indiceAlBuscar) { 1149 return true; 1150 } else { 1151 return false; 1152 } 1153 }); 1154 1155 let monedas_container = document.getElementById('monedasSelect'); 1156 1157 var html = ''; 1158 monedas_filtradas.forEach((moneda) => { 1159 html = html + `<option value="${moneda}">${moneda}</option>`; 1160 }); 1161 jQuery('#monedasSelect').html(html); 1162 1163 let monedas_index = document.getElementById('monedasSelect').options; 1164 1165 var moneda_selected = ''; 1166 if (document.getElementById('monedasSelect').selectedIndex >= 0) { 1167 if ( 1168 monedas_index[document.getElementById('monedasSelect').selectedIndex] 1169 .value !== undefined 1170 ) { 1171 moneda_selected = 1172 monedas_index[document.getElementById('monedasSelect').selectedIndex] 1173 .value; 1174 } 1175 } 1176 1177 if (productos.length !== 0) { 1178 productos.forEach((producto) => { 1179 //if (moneda_selected === producto.moneda) { 1180 let html = ` <div id="productoCarro-${producto.id}" class="mb-2 d-flex border-bottom"> 1181 <img id="checkProductos-${producto.id}" src="${urlImage}/seleccion.svg" class="pointer mr-4 imgProductos checkProductos" onclick="cambiar_selector(this,${producto.id})" data-producto="${producto.id}" data-select="selected"> 1182 1183 <span class="mr-1 w-50"> 1184 <span class="ml-1"><small> ${producto.descripcion} - </small></span> 1185 <span><small>${producto.precio} ${producto.moneda} - ${producto.periodo} </small></span> 1186 </span> 1187 1188 <div class="ml-auto w-25 d-flex"> 1189 <a class="font-weight-bold mx-1 pointer" onclick=eliminar_producto(${producto.id},1)> 1190 <span class="eliminar"> 1191 <i class="fas fa-times mr-1"></i> 1192 <small>Eliminar</small> 1193 </span> 1194 </a> 1195 </div> 1196 1197 </div>`; 1198 1199 listaProductos.insertAdjacentHTML('beforeend', html); 1200 //} 1201 1202 $('#cartModal').modal('show'); 1203 }); 1204 } 1205 1206 let productos_seleccionados = document.querySelectorAll('[data-producto]'); 1207 1208 /*productos_seleccionados.forEach((producto) => { 1209 producto.addEventListener("click", cambiar_selector, false); 1210 });*/ 1211 } else { 1212 if (checkUser == false) { 1213 $('#loginModal').modal('show'); 1214 } 1215 } 1216 cambiar_moneda(); 1217} 1218 1219function cambiar_selector_producto(producto, id) { 1220 let url = document.querySelector('[data-image]').dataset.image; 1221 1222 if ($('#checkProductos-' + id).data('select') === 'unselected') { 1223 $('#checkProductos-' + id).attr('src', `${url}/seleccion.svg`); 1224 $('#checkProductos-' + id).data('select', 'selected'); 1225 } else if ($('#checkProductos-' + id).data('select') === 'selected') { 1226 $('#checkProductos-' + id).attr('src', `${url}/deseleccionar.svg`); 1227 $('#checkProductos-' + id).data('select', 'unselected'); 1228 } 1229 1230 return true; 1231} 1232 1233function cambiar_moneda() { 1234 let productos = JSON.parse(document.getElementById('productos').value); 1235 1236 let listaProductos = document.getElementById('listaProductos'); 1237 1238 while (listaProductos.firstChild) { 1239 listaProductos.removeChild(listaProductos.firstChild); 1240 } 1241 1242 let urlImage = document.querySelector('[data-image]').dataset.image; 1243 1244 let monedas_index = document.getElementById('monedasSelect').options; 1245 1246 var moneda_selected = ''; 1247 if (document.getElementById('monedasSelect').selectedIndex >= 0) { 1248 if ( 1249 monedas_index[document.getElementById('monedasSelect').selectedIndex] 1250 .value !== undefined 1251 ) { 1252 moneda_selected = 1253 monedas_index[document.getElementById('monedasSelect').selectedIndex] 1254 .value; 1255 } 1256 } 1257 1258 if (productos.length !== 0) { 1259 productos.forEach((producto) => { 1260 if (moneda_selected === producto.moneda) { 1261 let html = ` <div id="productoCarro-${producto.id}" class="mb-2 d-flex"> 1262 <img id="checkProductos-${producto.id}" src="${urlImage}/seleccion.svg" class="pointer mr-4 imgProductos checkProductos" onclick="cambiar_selector(this,${producto.id})" data-producto="${producto.id}" data-select="selected"> 1263 1264 <span class="mr-1 w-50"> 1265 <span class="ml-1"><small> ${producto.descripcion} - </small></span> 1266 <span><small>${producto.precio} ${producto.moneda} - ${producto.periodo} </small></span> 1267 </span> 1268 1269 <div class="ml-auto w-25 d-flex"> 1270 <a class="font-weight-bold mx-1 pointer" onclick=eliminar_producto(${producto.id},1)> 1271 <span class="eliminar"> 1272 <i class="fas fa-times mr-1"></i> 1273 <small>Eliminar</small> 1274 </span> 1275 </a> 1276 </div> 1277 1278 </div>`; 1279 1280 listaProductos.insertAdjacentHTML('beforeend', html); 1281 } 1282 }); 1283 } 1284 1285 // ******************************************** 1286 // Seleccionar metodo de pago segun la moneda 1287 // ******************************************** 1288 car_productos = []; 1289 document.querySelector('[data-moneda="dolar"]').className = 'sr-only'; 1290 document.querySelector('[data-moneda="bolivar"]').className = 'sr-only'; 1291 switch (moneda_selected.toLowerCase()) { 1292 case 'dolar': 1293 document.querySelector('[data-moneda="dolar"]').className = 'pt-2 d-flex'; 1294 break; 1295 case 'bs': 1296 default: 1297 document.querySelector('[data-moneda="bolivar"]').className = 1298 'pt-2 d-flex'; 1299 break; 1300 } 1301}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.