/** * @collection Convert * @version 1.1.5 * @author Netzee * @site https://www.netzee.com.br */ !function(t,a){var r={customerId:null,loadCustomerId:function(){if(!r.customerId){const t=dataLayer.find(t=>"customerId"in t);r.customerId=t?t.customerId:null,console.log("cart.customerId",r.customerId)}},session:function(){return t("html").attr("data-session")},idStore:function(){return t("html").attr("data-store")},removeProduct:function(a){var e=parseInt(t(a).attr("data-id")),i="/"+t(a).attr("data-variant"),n=""==t(a).attr("data-add")?"":"/?additional_information="+t(a).attr("data-add").replace(/br>/g,"br/>"),o=""!==t(a).attr("data-together")?"/"+t(a).attr("data-together"):"";t.ajax({method:"DELETE",url:"/web_api/carts/"+r.session()+"/"+e+i+o+n,success:function(t){r.listProduct()},error:function(t){r.listProduct()}})},listProduct:function(){t.ajax({method:"GET",url:"/checkout/cart/api?session_id="+r.session()+"&store_id="+r.idStore()+"&nocache=0."+(new Date).getTime(),success:function(t){var a=t.data.cart.products,e=[];a.forEach(function(t){e.push({Cart:{email:"",variants_kit:t.variants_kit||"",additional_info_kit:t.additional_info_kit||"",price_itens_kit:t.price_itens_kit||"",product_id:t.id,product_name:t.name,quantity:t.quantity,price:t.price,variant_id:t.variant_id||"0",additional_information:t.additional_information,product_url:t.url,bought_together_id:t.bought_together_id||"",product_image:t.images}})}),r.forProduct(e)},error:function(){r.forProduct([])}})},number:function(a){t(".cart-header .number").text(a)},total:function(a){t(".cart-sidebar .total .value").text(toReal(parseFloat(a),""))},forProduct:function(a){var e=t(".cart-sidebar .content-cart .list");e.find("*").remove(),e.parent().removeClass("empty"),t(".modal-theme").removeClass("active"),t(".cart-header").addClass("active");var i=0,n=0,o=[];a.length?(a.forEach(function(t){var a=(t=t.Cart).additional_information.replace(/\//g,"");prices=t,e.append(r.templateProduct(t.product_id,t.variant_id,t.product_name,t.product_image.medium,t.quantity,t.price,t.price,t.product_url.https,a,t.additional_info_kit,t.bought_together_id)),i+=parseInt(t.quantity),n+=parseFloat(t.price)*parseInt(t.quantity),o.push(parseInt(t.product_id))}),r.number(i),r.total(n)):(e.append('
Carrinho Vazio
'),e.parent().addClass("empty"),r.number(0),t("body").find(".add-cart .buy-product").each(function(){t(this).hasClass("active")&&t(this).removeClass("active").find(".text").text("Comprar")}))},startCart:function(){t(".cart-header").on("click",".area",function(){t(this).parent().hasClass("active")?t(".cart-header").removeClass("active"):r.showCart()}),t("body").on("click",".shadow-cart, .shadow-cart-header, .box-prev, .close-nav,.box-fixed .close-box,.close-modal,.close-icon,.modal-theme .shadow",function(a){t(".cart-sidebar, .nav-mobile,.box-fixed,.modal-theme,.cart-header").removeClass("active")}),this.initAdd(),t(".product-submit").on("submit",function(a){a.preventDefault();var e=t(this).find(".select").val(),i=t(this).find(".quantity").val(),n=t(this).find(".quantity").attr("data-id");e&&r.addVariantComplete(e,i,n)}),t(".remove-items").on("click",function(){r.removeCart()})},removeCart:function(){t.ajax({method:"DELETE",url:"/web_api/carts/"+r.session(),success:function(t){r.listProduct()},error:function(t){r.listProduct()}})},showCart:function(){r.listProduct(),t(".header .menu").is(":visible")&&t("html, body").animate({scrollTop:0})},templateProduct:function(a,r,e,i,n,o,s,d,c,l,u){var m='
Qnt: {length}
{price}
';return m=(m=(m=(m=(m=(m=(m=(m=(m=m.replace(/{url}/g,d)).replace(/{image}/g,i)).replace(/{name}/g,e)).replace(/{id}/g,a)).replace(/{variant}/g,r)).replace(/{length}/g,n)).replace(/{addMsg}/g,c)).replace(/{together}/g,u)).replace(/{dataPrice}/g,o),s=toReal(parseFloat(s),t(".cart-header .number").data("moeda")),m=m.replace(/{price}/g,s)},addVariantComplete:function(e,i,n){r.loadCustomerId();const o={Cart:{session_id:r.session(),product_id:n,variant_id:e||0,quantity:i}};r.customerId&&(o.Cart.customer_id=r.customerId),t.ajax({method:"post",url:"/web_api/cart/",dataType:"json",data:o,success:function(t,a,e){r.showCart()},error:function(r,e,i){a.location.href=t(".modal-product").find(".name a").attr("href")}})},filterVariant:function(t,a){var r=0,e=a.eq(0).val();if(e)for(var i=a.eq(1).val();r'+n+'
'+o+"
"),Number(e.stock)>=i?t(a).removeClass("dont-stock"):t(a).addClass("dont-stock")},initAdd:function(){t("body").on("change",".add-cart input",function(){var a=Number(t(this).val());t(this).val(a>0?a:1)}),t("body").on("change",".list-variants select",function(){t(this).hasClass("first")?!t(this).parents(".list-variants").find(".second").val()&&t(this).parents(".list-variants").find(".second").length||r.stockAlert(t(this).parents(".list-variants")):t(this).parents(".list-variants").find(".first").val()&&r.stockAlert(t(this).parents(".list-variants"))}),t("body").on("submit",".list-variants",function(a){if(a.preventDefault(),t(this).hasClass("dont-stock"))return!1;var e=t(this).data("id"),i=t(this).find("input").val(),n=t(this).parents(".product").find("> a").attr("href"),o=t(this).data("variants").length?t(this).find("input").attr("data-variant"):0;r.addToCart(e,i,o,n)})},submitAdd:function(){t(".add-cart-modal").on("submit","form",function(a){a.preventDefault();var e=t(this).find("#product_modal").val(),i=t(this).find("#quant_modal").val(),n=t(this).find("#variant_modal");n.hasClass("required")?t("#alert-modal-add").removeClass("tray-hide"):(t(".action-add .add-cart").attr("disabled"),r.addVariantComplete(n.val(),i,e))})},addToCart:function(e,i,n,o){r.loadCustomerId();const s={Cart:{session_id:r.session(),product_id:e,variant_id:n||0,quantity:i}};r.customerId&&(s.Cart.customer_id=r.customerId),t.ajax({method:"post",url:"/web_api/cart/",dataType:"json",data:s,success:function(){r.showCart()},error:function(){a.location.href=o}})},ajaxGet:function(a,r){t.ajax({method:"GET",url:a,success:function(t){r(t)},error:function(t,a,e){r({error:!0});JSON.parse(t.responseText)}})}};r.startCart(),a.cart=r,t(".cart-sidebar").on("click",".remove",function(){r.removeProduct(this)}),t(".compreJunto").on("submit",function(){if(!t(this).find(".blocoAlerta").is(":visible"))var a=setInterval(function(){t(".cart-preview-loading-modal").hasClass("tray-hide")&&(r.showCart(),clearInterval(a))},50)})}(jQuery,window);