1async function dialogsCarrello(){const campionciniForm=document.querySelector("[data-campioncini-form]"),campioniciniLimitPlaceholder=document.querySelectorAll("[data-campioncini-limit]"),giftboxForm=document.querySelector("[data-giftbox-form]");async function getCart(){return await fetch(window.Shopify.routes.root+"cart.js").then(res=>res.json())}async function campionciniNelCarrello(cartItems2){const cartFullItems=cartItems2.map(({handle})=>fetch(`${window.Shopify.routes.root}products/${handle}.js`).then(res=>res.json()));return(await Promise.all(cartFullItems)).filter(prod=>prod.tags.includes("campioncino"))}function maxCampioncini(cartAmount){return cartAmount<=3900?2:cartAmount<=5900?3:cartAmount<=7900?4:5}function preselezionaCampioncini(campionciniInseriti2){const campionciniInseritiVariantID=campionciniInseriti2.map(prod=>prod.variants[0].id);[...campionciniForm.querySelectorAll('input[type="checkbox"]')].filter(cb=>campionciniInseritiVariantID.includes(+cb.value)).forEach(cb=>cb.checked=!0)}function opzioniCampionciniChangeHandler(maxCampioncini2){const campionciniSelezionati=campionciniForm.querySelectorAll('input[type="checkbox"]:checked'),numSelectedPlaceholder=document.querySelector("[data-campioncini-selected]");numSelectedPlaceholder.innerHTML=campionciniSelezionati.length,campionciniSelezionati.length>=maxCampioncini2?campionciniForm.querySelectorAll('input[type="checkbox"]:not(:checked)').forEach(cb=>cb.disabled=!0):campionciniForm.querySelectorAll('input[type="checkbox"]:not(:checked)').forEach(cb=>cb.disabled=!1)}async function updateCartUI(){try{const cartDrawer=document.querySelector("cart-drawer");let sectionsToRender=[];if(cartDrawer){const mainCartId=document.getElementById("main-cart-items")?.dataset.id;mainCartId?sectionsToRender=[{id:`#shopify-section-${mainCartId}`,section:mainCartId,selector:`#shopify-section-${mainCartId} cart-items`},{id:"#cart-counter",section:"cart-counter",selector:"#shopify-section-cart-counter"},{id:"#CartDrawer-Body",section:"cart-drawer",selector:"#shopify-section-cart-drawer #CartDrawer-Body"}]:sectionsToRender=[{id:"#CartDrawer-Body",section:"cart-drawer",selector:"#shopify-section-cart-drawer #CartDrawer-Body"}]}else{const mainCartId=document.getElementById("main-cart-items")?.dataset.id;mainCartId&&(sectionsToRender=[{id:`#shopify-section-${mainCartId}`,section:mainCartId,selector:`#shopify-section-${mainCartId} cart-items`},{id:"#cart-counter",section:"cart-counter",selector:"#shopify-section-cart-counter"}])}const body=JSON.stringify({sections:sectionsToRender.map(section=>section.section),sections_url:window.location.pathname}),parsedState=await(await fetch(window.Shopify.routes.root+"cart/update.js",{method:"POST",headers:{"Content-Type":"application/json"},body})).json();return sectionsToRender.forEach(section=>{const elementToReplace=document.querySelector(section.selector)||document.querySelector(section.id);elementToReplace&&parsedState.sections&&parsedState.sections[section.section]&&(elementToReplace.innerHTML=getSectionInnerHTML(parsedState.sections[section.section],section.selector))}),document.querySelectorAll("[data-cart-count]").forEach(el=>{el.textContent=parsedState.item_count}),document.dispatchEvent(new CustomEvent("cart:updated",{detail:parsedState})),parsedState}catch(error){throw console.error("Errore durante l'aggiornamento UI del carrello:",error),error}}function getSectionInnerHTML(html,selector){return new DOMParser().parseFromString(html,"text/html").querySelector(selector).innerHTML}async function updateDialogContent(){try{const{total_price:newTotalPrice,items:newCartItems}=await getCart(),newCampionciniInseriti=await campionciniNelCarrello(newCartItems),newCampionciniLimit=maxCampioncini(newTotalPrice);document.querySelectorAll("[data-campioncini-limit]").forEach(el=>{el.innerHTML=newCampionciniLimit}),campionciniForm&&campionciniForm.querySelectorAll('input[type="checkbox"]').forEach(cb=>{cb.checked=!1,cb.disabled=!1}),campionciniForm&&newCampionciniInseriti.length>0&&(preselezionaCampioncini(newCampionciniInseriti),opzioniCampionciniChangeHandler(newCampionciniLimit)),campionciniInseriti.length=0,campionciniInseriti.push(...newCampionciniInseriti),console.log("Dialog aggiornato con i nuovi campioncini")}catch(error){throw console.error("Errore durante l'aggiornamento del dialog:",error),error}}async function submitSamplesForm(e){e.preventDefault();const submitButton=e.target.querySelector('[type="submit"]');if(submitButton.disabled)return;submitButton.disabled=!0;const originalText2=submitButton.textContent;submitButton.textContent="Loading...";try{const idCampionciniSelezionati=[...e.target.querySelectorAll('[type="checkbox"]:checked')].map(cb=>cb.value);campionciniInseriti.length>0&&await removeCampionciniFromCart(),await addItemsSelezionati(idCampionciniSelezionati),await updateCartUI(),submitButton.disabled=!1,submitButton.textContent=originalText2,await updateDialogContent(),console.log("Campioncini aggiunti con successo al carrello!");const closeButton=document.querySelector("[js-close-samples]");closeButton&&closeButton.click()}catch(error){console.error("Errore durante il submit:",error),submitButton.disabled=!1,submitButton.textContent=originalText2;const errorDialog=document.querySelector("[data-campioncini-message]");errorDialog&&errorDialog.classList.add("is-open")}}async function removeCampionciniFromCart(){const payload=campionciniInseriti.reduce((acc,curr)=>(acc.updates[curr.variants[0].id]=0,acc),{updates:{}});return fetch(window.Shopify.routes.root+"cart/update.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(payload)}).then(res=>res.json())}async function addItemsSelezionati(idArray){const payload=idArray.reduce((acc,curr)=>(acc.items.push({id:parseInt(curr),quantity:1}),acc),{items:[]});return fetch(window.Shopify.routes.root+"cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(payload)}).then(res=>res.json())}function blockCart(){const messageModal=document.querySelector("[data-campioncini-message]");messageModal&&messageModal.classList.add("is-open");const interval=setInterval(()=>{const checkoutBtn=document.querySelector("form.cart-with-samples").querySelector('[type="submit"]');if(checkoutBtn.hasAttribute("data-saso")){clearInterval(interval);const fakeBtn=document.createElement("a");fakeBtn.classList.add("Cart__Checkout","Button","Button--primary"),fakeBtn.textContent=checkoutBtn.textContent,fakeBtn.style.cursor="pointer",fakeBtn.style.margin="0",fakeBtn.addEventListener("click",_e=>{messageModal.querySelector("[data-campioncini-limit]")&&(messageModal.querySelector("[data-campioncini-limit]").textContent=campionciniLimit),messageModal&&messageModal.classList.add("is-open")}),checkoutBtn.parentElement.append(fakeBtn),checkoutBtn.remove()}else checkoutBtn.disabled=!0,checkoutBtn.style.cursor="not-allowed"},500)}function preselezionaGiftbox(boxesInCart2){const boxesInCartVariantID=boxesInCart2.map(item=>item.id);[...giftboxForm.querySelectorAll('input[type="checkbox"]')].filter(cb=>
1boxesInCartVariantID.includes(+cb.value)).forEach(cb=>cb.checked=!0)}async function submitGiftboxForm(e){e.preventDefault();const submitButton=e.target.querySelector('[type="submit"]');if(!(submitButton&&submitButton.disabled)){if(submitButton){submitButton.disabled=!0;const originalText2=submitButton.textContent;submitButton.textContent="Loading..."}try{const idGiftboxSelezionati=[...e.target.querySelectorAll('[type="checkbox"]:checked')].map(cb=>cb.value);boxesInCart.length>0&&await removeGiftboxFromCart(),await addItemsSelezionati(idGiftboxSelezionati),await updateCartUI(),submitButton&&(submitButton.disabled=!1,submitButton.textContent=originalText);const dialog=e.target.closest("dialog");dialog&&dialog.close(),console.log("Gift box aggiunte con successo al carrello!")}catch(error){console.error("Errore durante il submit gift box:",error),submitButton&&(submitButton.disabled=!1,submitButton.textContent=originalText)}}}async function removeGiftboxFromCart(){const payload=boxesInCart.reduce((acc,curr)=>(acc.updates[curr.id]=0,acc),{updates:{}});return fetch(window.Shopify.routes.root+"cart/update.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(payload)}).then(res=>res.json())}const{total_price:totalPrice,items:cartItems}=await getCart(),campionciniInseriti=await campionciniNelCarrello(cartItems),campionciniLimit=maxCampioncini(totalPrice);campioniciniLimitPlaceholder.forEach(el=>el.innerHTML=campionciniLimit),campionciniForm&&campionciniInseriti.length>0&&preselezionaCampioncini(campionciniInseriti),campionciniForm&&campionciniInseriti.length>0&&opzioniCampionciniChangeHandler(campionciniLimit),campionciniForm&&campionciniForm.querySelectorAll('input[type="checkbox"]').forEach(cb=>cb.addEventListener("change",_e=>opzioniCampionciniChangeHandler(campionciniLimit))),campionciniForm&&campionciniForm.addEventListener("submit",submitSamplesForm),campionciniInseriti.length>campionciniLimit&&blockCart();const boxesVariantIds=giftboxForm?[...giftboxForm.querySelectorAll('input[type="checkbox"]')].map(cb=>parseInt(cb.value)):[],boxesInCart=boxesVariantIds.length>0?cartItems.filter(item=>boxesVariantIds.includes(item.id)):[];giftboxForm&&boxesInCart.length>0&&preselezionaGiftbox(boxesInCart),giftboxForm&&giftboxForm.addEventListener("submit",submitGiftboxForm)}dialogsCarrello(),document.addEventListener("cart:updated",async function(event){await dialogsCarrello()}),document.addEventListener("cart:item-removed",async function(event){await dialogsCarrello()}); 2//# sourceMappingURL=/cdn/shop/t/52/assets/ext-dialogs-carrello.js.map?v=151104611121387754371760020477
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.