/////////////////////////////////// SLIDER /////////////////////////////////////////////// //SLIDER MAIN const swiper = new Swiper(".swiper_top", { // Optional parameters direction: "horizontal", loop: true, autoplay: { delay: 5000, }, }); const swiperResponsive = new Swiper(".swiper_top_responsive", { // Optional parameters direction: "horizontal", loop: true, autoplay: { delay: 5000, }, }); //SLIDER DESTACADOS var swiperRemarkable = new Swiper(".swiper-remarkable", { slidesPerView: "auto", spaceBetween: 7, navigation: { nextEl: ".swiper-button-next-remarkable", prevEl: ".swiper-button-prev-remarkable", }, }); // //SLIDER OFFERS // var swiperOffers = new Swiper('.swiper-offers', { // slidesPerView: 'auto', // spaceBetween: 7, // navigation: { // nextEl: '.swiper-button-next-offers', // prevEl: '.swiper-button-prev-offers', // }, // }); //SLIDER OFFERS var swiperOffers = new Swiper(".swiper-offers1", { slidesPerView: "auto", spaceBetween: 7, navigation: { nextEl: ".swiper-button-next-offers1", prevEl: ".swiper-button-prev-offers1", }, }); //SLIDER OFFERS var swiperOffers = new Swiper(".swiper-offers4", { slidesPerView: "auto", spaceBetween: 7, navigation: { nextEl: ".swiper-button-next-offers4", prevEl: ".swiper-button-prev-offers4", }, }); //SLIDER IMAGES DETALLE var swiperDetails = new Swiper(".swiper-img", { spaceBetween: 10, slidesPerView: 4, freeMode: true, watchSlidesVisibility: true, watchSlidesProgress: true, }); /////////////////////////////////// LINKS INSIDE /////////////////////////////////////////////// $('a[href*="#"]') // Remove links that don't actually link to anything .not('[href="#"]') .not('[href="#0"]') .click(function (event) { // On-page links if ( location.pathname.replace(/^\//, "") == this.pathname.replace(/^\//, "") && location.hostname == this.hostname ) { // Figure out element to scroll to var target = $(this.hash); target = target.length ? target : $("[name=" + this.hash.slice(1) + "]"); // Does a scroll target exist? if (target.length) { // Only prevent default if animation is actually gonna happen event.preventDefault(); $("html, body").animate( { scrollTop: target.offset().top - 120, }, 1000, function () {} ); } } }); /////////////////////////////////// MENUS /////////////////////////////////////////////// function openCloseMenu() { if ($("#menu").css("display") == "block") { $("#menu").animate({ width: "toggle" }); $(".menu_right").animate({ width: "toggle" }); $("body").css("overflow-y", "scroll"); // $('#overlayMenu').css('display','none'); // $(".fondo_black_header").attr("style", "display: none;"); // $('.menu_responsive').css('transform', 'translate(-4000px, 0)'); } else { $("#menu").animate({ width: "toggle" }); $(".menu_right").animate({ width: "toggle" }); $("body").css("overflow-y", "hidden"); // $('#overlayMenu').css('display','block'); // $(".fondo_black_header").attr("style", "display: block;"); } } function closeMenu() { // if (screen.width < 960) { $("#menuToggle input").prop("checked", ""); $("#menu").animate({ width: "toggle" }); $("body").css("overflow-y", "scroll"); $("#overlayMenu").css("display", "none"); // } } //CLOSE OFFER function closeOffer() { $(".offer_header").slideUp(200); } //OPEN MENU PRODUCT RESPONSIVE function openMenuProductResponsive(category) { $("#wrap-" + category).slideToggle(200); if ($("#less-" + category).css("display") == "block") { $("#plus-" + category).css("transform", "rotate(540deg)"); $("#less-" + category).css("display", "none"); $("#less-" + category).css("transform", "rotate(90deg)"); } else { $("#plus-" + category).css("transform", "rotate(90deg)"); $("#less-" + category).css("display", "block"); $("#less-" + category).css("transform", "rotate(540deg)"); } } //ABRIR Y CERRAR FILTROS function openCloseFilters(content) { if ($(".checkboxs_" + content).attr("style") === "display: block;") { $(".checkboxs_" + content).attr("style", "display: none;"); $(".arrow_" + content).attr("style", "transform: rotate(0deg)"); $(".arrow_" + content).css("fill", "#c4c4c4"); } else { $(".checkboxs_" + content).attr("style", "display: block;"); $(".arrow_" + content).attr("style", "transform: rotate(180deg)"); $(".arrow_" + content).css("fill", "#000"); } } function dropFilter() { if ($(".fondo_black_header").attr("style") === "display: none;") { $(".filter").addClass("is_active"); $(".fondo_black_header").attr("style", "display: block;"); $(".content_header_flotante").css("z-index", "170"); } else { $(".fondo_black_header").attr("style", "display: none;"); $(".filter").removeClass("is_active"); $(".content_header_flotante").css("z-index", "190"); } } // PRODUCT MENU // if ($(window).width() > 960) { $("#itemCateHeader input").click(function (e) { $(".product_menu").toggleClass("is_hover"); $("#itemCateHeader").toggleClass("is_hover"); $(".fondo_black_header").toggleClass("is_hover"); $("body").toggleClass("is_hover"); }); $(".category_menu").hover(function (e) { $(".item_cat_menu_desp").each(function () { $(this).removeClass("is_hover"); }); $(this).addClass("is_hover", e.type === "mouseenter"); $(this).toggleClass("is_active", e.type === "mouseenter"); idGrp = $(this).attr("id").split("_")[1]; $(".img_menu").each(function () { $(this).removeClass("is_hover"); }); $("#imgCat_" + idGrp).addClass("is_hover"); }); //SEARCH FLOAT $(".search_btn").click(function () { if ($(".search_responsive").attr("style") === "display: none;") { $(".search_responsive").attr("style", "display: flex;"); } else { $(".search_responsive").attr("style", "display: none;"); } }); function floatSearch() { $(".search_float").css("display", "flex"); } //SEARCH SET BUTTON function setButtonSearch() { if ($(".expandright").css("padding") === "0 0 0 16px;") { $("#formBusqueda").submit(); } } // //CATEGORY HOVER // function toggleCategoryChild(categoryId){ // $("#category_"+categoryId).hover( function (e) { // $('#childMenu_'+categoryId).slideToggle(200); // }); // } /////////////////////////////////// BUTTON DETAILS QUANTITY /////////////////////////////////////////////// function incrementList(idProduct) { quantity = $("#cantidad_" + idProduct).val(); quantity = parseInt(quantity) + 1; if (quantity != 0) { $("#cantidad_" + idProduct).val(quantity); } $("#cantidad_" + idProduct).focus(); return false; } function decrementList(idProduct) { quantity = $("#cantidad_" + idProduct).val(); quantity = parseInt(quantity) - 1; if (quantity != 0) { $("#cantidad_" + idProduct).val(quantity); } $("#cantidad_" + idProduct).focus(); return false; } ///////////////////////////////////formatMoney///////////////////////////////////////////////// function formatMoney(amount, decimalCount = 2, decimal = ".", thousands = ",") { try { decimalCount = Math.abs(decimalCount); decimalCount = isNaN(decimalCount) ? 2 : decimalCount; const negativeSign = amount < 0 ? "-" : ""; let i = parseInt( (amount = Math.abs(Number(amount) || 0).toFixed(decimalCount)) ).toString(); let j = i.length > 3 ? i.length % 3 : 0; return ( negativeSign + (j ? i.substr(0, j) + thousands : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands) + (decimalCount ? decimal + Math.abs(amount - i) .toFixed(decimalCount) .slice(2) : "") ); } catch (e) { console.log(e); } } ///////////////////////////////////FORM CONTACTO///////////////////////////////////////////////// function enviarForm(idFrm, template = "form.php") { if ($("#" + idFrm).isValid({}, {}, true)) { $("#layerLoad").css("display", "block"); $.post("/" + template, $("#" + idFrm).serialize(), function (data) { $("#layerLoad").css("display", "none"); $("#layerMailOk").fadeIn("fast"); setTimeout(function () { $("#layerMailOk").fadeOut("fast"); }, 4000); }); if ($("input[name=category]")) { $.post("/leads/add", $("#" + idFrm).serialize(), function (data) { return false; }); } if (idFrm == "formContacto") { dataLayer.push({ event: "form_contacto_sended", }); } if (idFrm == "formCotizador") { dataLayer.push({ event: "form_cotizador_sended", }); } } } ///////////////////////////////////NEWSLETTER///////////////////////////////////////////////// function suscribeNewsletter(idFrm) { // if($("#"+idFrm).isValid({}, {}, true)) { $("#layerLoad").css("display", "block"); $.post("/leads/add", $("#" + idFrm).serialize(), function (data) { $("#" + idFrm + " input").each(function () { $(this).val(""); }); $("#layerLoad").css("display", "none"); $("#layerMailOk").fadeIn("fast"); setTimeout(function () { $("#layerMailOk").fadeOut("fast"); }, 4000); return false; }); return false; // } } // $('.detail_product').fancybox(); // function getDetailsProduct(idProduct){ // var rand = Math.round(100*Math.random()); // IE CACHE FIX // jQuery.post( '/getPlugin.php','action=getProducts&id='+idProduct +'&template=get_details_product&_nocache='+rand,function(response,status,xhr){ // if (status == "error") { // var msg = "Lo sentimos pero ocurrió un error: "; // alert(msg + xhr.status + " " + xhr.statusText); // } // else{ // } // }); // } const showVariantLoading =(state)=>{ if(state){ $("#variants_loader").show() }else{ $("#variants_loader").hide() } } const showShareCartLoading =(state)=>{ if(state){ $("#share_cart_loader").css("display", "flex"); }else{ $("#share_cart_loader").css("display", "none"); } } function getVariantAttributes(product) { showVariantLoading(true) arrAttributesSelected = new Array(); $(".selectVariants").each(function () { if ($(this).val() != "") { arrAttributesSelected.push($(this).val()); } }); attributesSelected = JSON.stringify(arrAttributesSelected); var rand = Math.round(100 * Math.random()); // IE CACHE FIX jQuery.post( "/getPlugin.php", "action=getVariantsAttributes&product=" + product + "&attributes=" + attributesSelected + "&template=attributes_variants&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { var msg = "Lo sentimos pero ocurrió un error: "; alert(msg + xhr.status + " " + xhr.statusText); showVariantLoading(false) } else { $("#variantOptions").append(response); showVariantLoading(false) } } ); } function getVariantAttributeValues(product) { arrAttributesSelected = new Array(); arrAttribute = new Array(); nextAttribute = ""; showVariantLoading(true) $(".selectVariants").each(function () { arrAttribute.push({ id: $(this).attr("id"), value: $(this).val() }); if ($(this).val() != "") { arrAttributesSelected.push($(this).val()); } }); j = 0; for (var i = 0; i < arrAttribute.length; i++) { if (arrAttribute[i]["value"] != "") { j++; } } if (j < arrAttribute.length) { nextAttribute = arrAttribute[j]["id"]; } else { nextAttribute = "changeVariant"; } attributesSelected = JSON.stringify(arrAttributesSelected); var rand = Math.round(100 * Math.random()); // IE CACHE FIX jQuery.post( "/getPlugin.php", "action=getVariantsAttributesValues&product=" + product + "&attributes=" + attributesSelected + "&template=attributes_variants_options&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { var msg = "Lo sentimos pero ocurrió un error: "; alert(msg + xhr.status + " " + xhr.statusText); showVariantLoading(false) } else { $("#" + nextAttribute).html(response); $("#changeVariantInput").val(response); showVariantLoading(false) } } ); } function changeVariant(variant) { var rand = Math.round(100 * Math.random()); // IE CACHE FIX showVariantLoading(true) jQuery.post( "/getPlugin.php", "action=getVariant&id=" + variant + "&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { var msg = "Lo sentimos pero ocurrió un error: "; alert(msg + xhr.status + " " + xhr.statusText); showVariantLoading(false) } else { var objData = jQuery.parseJSON(response); // $('#imgPrincipal').html(''); showVariantLoading(false) } } ); } function selectVariant(product, variant) { showVariantLoading(true) var rand = Math.round(100 * Math.random()); // IE CACHE FIX jQuery.post( "/getPlugin.php", "action=getVariant&id=" + variant + "&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { var msg = "Lo sentimos pero ocurrió un error: "; alert(msg + xhr.status + " " + xhr.statusText); showVariantLoading(false) } else { var objData = jQuery.parseJSON(response); if (objData.offer) { $(".priceDetail_" + product).html( "$" + formatMoney(objData.offer, 0, ",", ".") ); } else { if (Number(objData.price) === 0) { $(".priceDetail_" + product).html(""); } else { $(".priceDetail_" + product).html( "$" + formatMoney(objData.price, 0, ",", ".") ); } } // calcSubtotal($('#cantidad_"+product+"'), objData.price.replace('.',',')); $("#oldPrice_" + product).css("display", "none"); console.log(' objData',Number(objData?.stock) > 0) if (Number(objData?.stock) > 0 && Number(objData.price) > 0) { console.log('objData.stock', objData.stock) $("#btnComprar").attr( "onclick", "addProductToCart('" + product + "', '" + variant + "', $('#cantidad_" + product + "').val()); $.fancybox.close();" ); $("#btnComprar").attr("class", "buy"); $("#wrpQuantity").css("display", "flex"); $("#btnComprar").html(`
Sumar al pedido`); // $('#btnComprar').html('
Sumar al carro
'); } else { $("#btnComprar").attr("onclick", "location.href='/contacto.html'"); $("#btnComprar").attr("class", "buy buy_nostock"); $("#wrpQuantity").css("display", "none"); $("#btnComprar").html("CONSULTAR"); } const varianteSeleccionada = temporalAattributes.find(item => item.id == objData.id); if (varianteSeleccionada) { $('#selectColorVariantes').text(varianteSeleccionada.name); } if(objData?.images?.length<= 0 || !objData?.images[0]|| objData.images[0] === undefined){ $('#imgPrincipal').attr("src",`/images/img_no_disponible.jpg`); }else{ if(objData.images.length > 1){ $('.hidden_variant').each(function() { $(this).hide(); }) ; $(`.variant_${variant}`).show(); let swiperInstances = new Swiper(`.swiper-img-mini_${variant}`, { direction: 'horizontal', navigation: { nextEl: `.swiper-button-next-details_${variant}`, prevEl: `.swiper-button-prev-details_${variant}`, } }); // $(`.variant_${variant}`).each(function () { // swiperInstances{{ variant }}.update(); // swiperInstances{{ variant }}.updateSize(); // }); }else{ $('#imgPrincipal').attr("src",`/images/uploads/ecommerce/variants/${ objData.images[0]}`); } } showVariantLoading(false); } } ); } function openProductDetails(productId, productUrl) { $.fancybox.open({ src: "/ecommerce/" + productUrl, type: "ajax", opts: { toolbar: false, defaultType: "ajax", autoFocus: true, touch: false, afterLoad: function () { new Swiper(".swiper-img-mini", { direction: "horizontal", navigation: { nextEl: ".swiper-button-next-details", prevEl: ".swiper-button-prev-details", }, }); }, }, }); } function initTicket() { var rand = Math.round(100 * Math.random()); // IE CACHE FIX jQuery.post( "/getPlugin.php", "module=ecommerce&abstraction=front&action=getCart&template=carro_lateral&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { var msg = "Lo sentimos pero ocurrió un error: "; alert(msg + xhr.status + " " + xhr.statusText); } else { $("#carroLateral").html(response); } } ); } function addProductToCart(idProduct, variante, quantity) { if (variante == "null") { alertPM("Debe seleccionar una variante para poder comprar este producto"); } else { var rand = Math.round(100 * Math.random()); // IE CACHE FIX jQuery.post( "/getPlugin.php", "action=addProductToCart&id=" + idProduct + "&variant=" + variante + "&quantity=" + quantity + "&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { var msg = "Lo sentimos pero ocurrió un error: "; alert(msg + xhr.status + " " + xhr.statusText); } else { if (response == 0) { $("#infoEmergente").html( "La cantidad a agregar al carro supera al stock del artículo" ); $("#infoEmergente").fadeIn("fast"); setTimeout(function () { $("#infoEmergente").fadeOut("fast"); }, 4000); } else { // $('#cartHeader').html(response); // $('#carroHeader').slideDown('fast', function(){}); // $('#infoEmergente').html('Producto agregado con éxito al carro de compras'); // $('#infoEmergente').fadeIn('fast'); // setTimeout(function(){$('#infoEmergente').fadeOut('fast');}, 3000); initTicket(); openCloseCarroLat(); // $('#variantOptions').html(''); // getVariantAttributes(idProduct); productName = $("#description_" + idProduct).text(); productPrice = $("#price_" + idProduct).text(); productPrice = productPrice.replace(",", ".").substring(1); productPrice = parseFloat(productPrice); dataLayer.push({ event: "add_to_cart", ecommerce: { items: [{ item_id: idProduct, item_name: productName, item_variant: variante, price: productPrice, quantity: quantity }] } }); } } } ); } } function deleteProductToCart(idProduct, variante) { var rand = Math.round(100 * Math.random()); // IE CACHE FIX jQuery.post( "/getPlugin.php", "action=deleteProductToCart&id=" + idProduct + "&variant=" + variante + "&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { var msg = "Lo sentimos pero ocurrió un error: "; alert(msg + xhr.status + " " + xhr.statusText); } else { if (response == 0) { loadCart(); $("#infoEmergente").html("NO HAY STOCK DISPONIBLE"); $("#infoEmergente").fadeIn("fast"); setTimeout(function () { $("#infoEmergente").fadeOut("fast"); }, 4000); } else { $("#cart").html(response); initTicket(); $("#infoEmergente").html( "Producto eliminado con éxito del carro de compras" ); $("#infoEmergente").fadeIn("fast"); setTimeout(function () { $("#infoEmergente").fadeOut("fast"); }, 3000); } } } ); } function updateCart(idProduct, variante) { quantity = $("#input_cantidad_carro_" + idProduct).val(); var rand = Math.round(100 * Math.random()); // IE CACHE FIX jQuery.post( "/getPlugin.php", "action=updateProductToCart&id=" + idProduct + "&variant=" + variante + "&quantity=" + quantity + "&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { var msg = "Lo sentimos pero ocurrió un error: "; alert(msg + xhr.status + " " + xhr.statusText); } else { if (response == 0) { loadCart(); $("#infoEmergente").html( "La cantidad a agregar al carro supera al stock del artículo" ); $("#infoEmergente").fadeIn("fast"); setTimeout(function () { $("#infoEmergente").fadeOut("fast"); }, 4000); } else { initTicket(); loadCart(); $("#cart").html(response); $("#infoEmergente").html( "Producto modificado con éxito en el carro de compras" ); $("#infoEmergente").fadeIn("fast"); setTimeout(function () { $("#infoEmergente").fadeOut("fast"); }, 3000); } } } ); } function incrementCart(idProduct, variante) { quantity = $("#input_cantidad_carro_" + idProduct).val(); quantity = parseInt(quantity) + 1; if (quantity != 0) { var rand = Math.round(100 * Math.random()); // IE CACHE FIX jQuery.post( "/getPlugin.php", "action=updateProductToCart&id=" + idProduct + "&variant=" + variante + "&quantity=" + quantity + "&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { var msg = "Lo sentimos pero ocurrió un error: "; alert(msg + xhr.status + " " + xhr.statusText); } else { if (response == 0) { loadCart(); $("#infoEmergente").html( "La cantidad a agregar al carro supera al stock del artículo" ); $("#infoEmergente").fadeIn("fast"); setTimeout(function () { $("#infoEmergente").fadeOut("fast"); }, 4000); } else { initTicket(); loadCart(); $("#cart").html(response); $("#infoEmergente").html( "Producto modificado con éxito en el carro de compras" ); $("#infoEmergente").fadeIn("fast"); setTimeout(function () { $("#infoEmergente").fadeOut("fast"); }, 3000); } } } ); } return false; } function decrementCart(idProduct, variante) { quantity = $("#input_cantidad_carro_" + idProduct).val(); quantity = parseInt(quantity) - 1; if (quantity != 0) { var rand = Math.round(100 * Math.random()); // IE CACHE FIX jQuery.post( "/getPlugin.php", "action=updateProductToCart&id=" + idProduct + "&variant=" + variante + "&quantity=" + quantity + "&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { var msg = "Lo sentimos pero ocurrió un error: "; alert(msg + xhr.status + " " + xhr.statusText); } else { if (response == 0) { loadCart(); $("#infoEmergente").html( "La cantidad a agregar al carro supera al stock del artículo" ); $("#infoEmergente").fadeIn("fast"); setTimeout(function () { $("#infoEmergente").fadeOut("fast"); }, 4000); } else { initTicket(); loadCart(); $("#cart").html(response); $("#infoEmergente").html( "Producto modificado con éxito en el carro de compras" ); $("#infoEmergente").fadeIn("fast"); setTimeout(function () { $("#infoEmergente").fadeOut("fast"); }, 3000); } } } ); } return false; } function loadCart() { var rand = Math.round(100 * Math.random()); // IE CACHE FIX jQuery.post( "/getPlugin.php", "action=getCart&template=get_cart&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { var msg = "Lo sentimos pero ocurrió un error: "; alert(msg + xhr.status + " " + xhr.statusText); } else { $("#cart").html(response); } } ); } function getShipping() { cpostal = $("#cpostal").val(); if (cpostal.length >= 4) { $("#layerLoadShipping").css("display", "block"); var rand = Math.round(100 * Math.random()); // IE CACHE FIX jQuery.post( "/getPlugin.php", "module=ecommerce&abstraction=front&action=getShipping&postcode=" + cpostal + "&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { var msg = "Lo sentimos pero ocurrió un error: "; alert(msg + xhr.status + " " + xhr.statusText); return false; } else { $("#shipping").html(response); return false; } $("#layerLoadShipping").css("display", "none"); } ); } return false; } function selectEnvio(checkbox, gatewayShippingType = null, gatewayShippingBranchId = null, carrier_id = null) { $("#layerLoadShipping").css("display", "block"); $('input[name="checkoutEnvio[]"]').each(function () { $(this).prop("checked", false); }); $(checkbox).prop("checked", true); cpostal = $("#cpostal").val(); id = $(checkbox).val(); var rand = Math.round(100 * Math.random()); // IE CACHE FIX jQuery.post( "/getPlugin.php", "module=ecommerce&abstraction=front&action=addShippingToCart&id=" + id + "&gatewayShippingType=" + gatewayShippingType + "&postcode=" + cpostal + "&gatewayShippingBranchId=" + gatewayShippingBranchId + '&carrier_id='+ carrier_id+ "&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { var msg = "Lo sentimos pero ocurrió un error: "; alert(msg + xhr.status + " " + xhr.statusText); } else { var objData = jQuery.parseJSON(response); $("#envioCarro").html("$" + objData["send"]); $("#subTotalCarro").html("$" + objData["total"]); $("#totalFinal").html("TOTAL: $" + objData["total"]); } $("#layerLoadShipping").css("display", "none"); } ); } function getCart() { paymentMethod = $("input[name=payment_method]:checked").val(); installment = $("#installment").val(); var rand = Math.round(100 * Math.random()); // IE CACHE FIX jQuery.post( "/getPlugin.php", "module=ecommerce&abstraction=front&action=getCart&payment_method=" + paymentMethod + "&installment=" + installment + "&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { var msg = "Lo sentimos pero ocurrió un error: "; alert(msg + xhr.status + " " + xhr.statusText); } else { var objData = jQuery.parseJSON(response); $("#envioCarro").html("$" + objData["send"]); $("#taxCarro").html("$" + objData["tax"]); $("#discountCarro").html("- $" + objData["discount"]); $("#subTotalCarro").html("$" + objData["total"]); $("#totalFinal").html("TOTAL: $" + objData["total"]); } } ); } function changeOrder() { ordenador = $("#ordenador").val(); ordenador = ordenador.split("_"); $("#order").val(ordenador[0]); $("#order_type").val(ordenador[1]); $("#formEcommerce").submit(); } function changeImageDetalle(imgChica) { $("#imageZoom").attr("src", $(imgChica).attr("src")); $("#linkImgPrinc").attr("href", $(imgChica).attr("src")); if (screen.width >= 960) { $("#zoom").zoom(); // $('#imageZoom').attr('data-zoom-image', $(imgChica).attr('data-zoom-image')); // $("#imageZoom").data('zoom-image', $(imgChica).attr('data-zoom-image')).elevateZoom({scrollZoom : true, borderSize: 0}); } } function openCloseCarroLat() { if ($("#carroLat").length > 0) { if ($(".carro_lateral").css("right") == "-375px") { $(".carro_lateral").animate({ right: "0px" }, "fast"); $("#overlayCart").css("display", "block"); $("body").css("overflow-y", "hidden"); } else { $(".carro_lateral").animate({ right: "-375px" }, "fast"); $("#overlayCart").css("display", "none"); $("body").css("overflow-y", "scroll"); } } else { location.href = "/users/get-login"; } } function changeMetodoPago(metodo) { if (metodo == "mercadopago") { $(".content_redireccion_mp").css("display", "block"); } else { $(".content_redireccion_mp").css("display", "none"); } getCart(); } // function changeSelecBtnOferta(btnOferta,idDestacado){ // $('.btn_oferta_selec').removeClass('btn_oferta_selec').addClass('btn_oferta'); // $(btnOferta).addClass('btn_oferta_selec').removeClass('btn_oferta'); // $('.content_prod_destacados').each(function(){ // $(this).css('display','none'); // }); // $('#'+idDestacado).slideDown(400); // } /////////////////////////////////// LOGIN /////////////////////////////////////////////// function openRegisterForm() { $("#newLogin").animate({ left: "-600px" }, 800); $("#newRegister").animate({ left: "0px" }, 800); $("#contentLoginRegistro").animate({ height: "680px" }, 800); $("#pageLogin").css("background-color", "#fad000"); } function closeRegisterForm() { $("#newLogin").animate({ left: "0px" }, 800); $("#newRegister").animate({ left: "600px" }, 800); $("#contentLoginRegistro").animate({ height: "380px" }, 800); $("#pageLogin").css("background-color", "#e6e6e6"); } function addUser(idFrm) { if ($("#" + idFrm).isValid({}, {}, true)) { if ($("#pass").val() == $("#confirmpass").val()) { $.post( "/getPlugin.php?action=addUser", $("#" + idFrm).serialize(), function (data) { if (data == "OK") { location.href = "/"; } else { alertPM(data); } } ); } else { alertPM("No coinciden las contraseñas ingresadas"); } } return false; } /////////////////////////////////// GETPARAMETER /////////////////////////////////////////////// function getParameter(parameter) { var url = location.href; var index = url.indexOf("?"); index = url.indexOf(parameter, index) + parameter.length; if (url.charAt(index) == "=") { var result = url.indexOf("&", index); if (result == -1) { result = url.length; } var puesto = decodeURI(url.substring(index + 1, result)); return puesto; } } function getCodDescuento() { codDesc = $("#cod_descuento").val(); var rand = Math.round(100 * Math.random()); // IE CACHE FIX jQuery.post( "/getPlugin.php", "module=ecommerce&action=addCuponToCart&code=" + codDesc + "&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { var msg = "Lo sentimos pero ocurrió un error: "; alert(msg + xhr.status + " " + xhr.statusText); } else { var objData = jQuery.parseJSON(response); console.log(objData); $("#descuentoCarro2").html( "-$" + objData["totalDiscount"].replace(".", ",") ); $("#discountCarro").html( "-$" + objData["totalDiscount"].replace(".", ",") ); $("#totalCarro2").html("$" + objData["total"]); $("#totalFinal").html("$" + objData["total"]); // console.log(objData['cuponId']); if (objData["cuponId"] == "") { $("#textDescuentoCarro").html("Descuento"); $("#infoEmergente").html( "El Código no existe o se encuentra vencido" ); $("#infoEmergente").slideDown("fast"); setTimeout(function () { $("#infoEmergente").slideUp("fast"); }, 3500); } else { $("#infoEmergente").attr("style", "background-color:#6cb472;"); $("#infoEmergente").html( "Aplicado con éxito el cupón " + objData["cuponCode"] + " (" + objData["discountPercentage"] + "%)" ); $("#infoEmergente").slideDown("fast"); setTimeout(function () { $("#infoEmergente").slideUp("fast"); $("#infoEmergente").attr("style", ""); }, 3500); $("#textDescuentoCarro").html( "Descuento
Cupón: " + objData["cuponCode"] + " (" + objData["discountPercentage"] + "%)" ); } } } ); } function shareCart() { var rand = Math.round(100 * Math.random()); // IE CACHE FIX const button_share_cart = document.querySelector('.button_share_cart'); console.log('holaaaaaaaa'); showShareCartLoading(true); console.log('hola shareCart'); jQuery.post( "/getPlugin.php", "module=ecommerce&abstraction=front&action=getCart&return=json&_nocache=" + rand, function (response, status, xhr) { if (status == "error") { console.error("Error obteniendo datos del carrito:", xhr.status + " " + xhr.statusText); } else { try { var cartData = jQuery.parseJSON(response); console.log("Datos del carrito:", cartData); if (cartData.lines && cartData.lines.length > 0) { const productosArray = cartData.lines.map(function(line) { const productId = line.productId; const quantity = line.quantity; const variantId = line.variantId ? `|${line.variantId}` : ''; console.log("productId", productId, "quantity", quantity, "variantId", variantId); return `${productId}${variantId}-${quantity}`; }); const productosParam = productosArray.join(","); const url = `https://www.berkanaoficial.com/share_cart.html?productos=${productosParam}`; console.log("URL generada:", url); copyToClipBoard(url, button_share_cart); } else { console.log("El carrito está vacío"); } } catch (e) { console.error("Error parseando respuesta del carrito:", e); console.log("Respuesta recibida:", response); } } } ); } ////////// SHARE /////////////////////////////////// const copyToClipBoard = (content, clickedEl) => { if (window.isSecureContext && navigator.clipboard) { navigator.clipboard.writeText(content).then(() => { if (clickedEl) { const $btn = $(clickedEl); if ($btn.find(".tooltip").length === 0) { $btn.append('
COPIADO
'); } else { $btn.find(".tooltip").text("COPIADO"); } $btn.addClass("show-tooltip"); setTimeout(() => { $btn.removeClass("show-tooltip"); }, 2000); showShareCartLoading(false); } }).catch(() => { if (clickedEl) { const $btn = $(clickedEl); if ($btn.find(".tooltip").length === 0) { $btn.append('
Error al copiar
'); } else { $btn.find(".tooltip").text("Error al copiar"); } $btn.addClass("show-tooltip"); setTimeout(() => { $btn.removeClass("show-tooltip"); }, 2000); } console.error("No se pudo copiar"); showShareCartLoading(false); }); } else { if (clickedEl) { const $btn = $(clickedEl); if ($btn.find(".tooltip").length === 0) { $btn.append('
No es posible copiar
'); } else { $btn.find(".tooltip").text("No es posible copiar"); } $btn.addClass("show-tooltip"); setTimeout(() => { $btn.removeClass("show-tooltip"); }, 2000); } console.error("No es un contexto seguro o no hay soporte para Clipboard API"); showShareCartLoading(false); } }; const scrollToTop=()=>{ window.scrollTo({top: 0, behavior: 'smooth'}); }