1function handleCartIconUpdate(itemsCount){const cartIcon=document.querySelector(".header__icon--cart");cartIcon&&(itemsCount>0?cartIcon.classList.add("cart__toggle--has-items"):cartIcon.classList.remove("cart__toggle--has-items"))}const cartFoot=document.querySelector(".cart-drawer__foot.cart__foot"),jsonProduct=JSON.parse(document.querySelector("#gift__products").innerHTML),jsonVariantList=JSON.parse(document.querySelector("#product-list_variant").innerHTML),removeEmptyField=jsonProduct.filter(el=>el.free!==""),removeEmptyFieldVariantList=jsonVariantList.filter(el=>el.free!==""),allJson=[...removeEmptyField,...removeEmptyFieldVariantList];allJson.forEach(obj=>{obj.free=obj.free.split(",").map(id=>id.trim()).filter(id=>id!=="")});async function handleCartUpdate(items){handleCartIconUpdate(items.length);const updates={},freeProducts=items.filter(item=>item.price===0);for(const freeProduct of freeProducts){const{quantity,id}=freeProduct;quantity>1&&(updates[id]=1)}const hasBooklet=items.filter(item=>item.variant_id===48079822979227),subscriptionItemIds=items.filter(item=>item.selling_plan_allocation).map(item=>Number(item.product_id));for(const freeProduct of freeProducts){if(hasBooklet&&freeProduct.product_type?.toLowerCase().includes("gel"))continue;const rules=allJson.filter(obj=>obj.free.some(f=>Number(f)===Number(freeProduct.product_id)));let hasParent=!1;for(const rule of rules)if(rule.main.split(",").map(id=>Number(id.trim())).some(id=>subscriptionItemIds.includes(id))){hasParent=!0;break}console.log("DEBUG free gift check:",{freeProductId:freeProduct.product_id,freeProductVariantId:freeProduct.id,matchingRules:rules,subscriptionItemIds,mainIdsFromRules:rules.map(r=>r.main.split(",").map(id=>id.trim())),hasMatch:rules.some(rule=>rule.main.split(",").map(id=>Number(id.trim())).some(m=>subscriptionItemIds.includes(m)))}),hasParent||(document.querySelector(".body-loader").classList.add("active"),updates[freeProduct.id]=0)}if(Object.keys(updates).length!==0)try{cartFoot&&cartFoot.classList.add("is-disabled");const response=await fetch(window.Shopify.routes.root+"cart/update.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({updates})});if(!response.ok)throw new Error("Failed to update cart");const data=await response.json();handleCartIconUpdate(data.item_count),document.dispatchEvent(new CustomEvent("cart:update"))}catch(error){console.error("Error updating cart:",error)}finally{cartFoot&&cartFoot.classList.remove("is-disabled")}}subscribe(window.PUB_SUB_EVENTS?.cartUpdate||"cart-update",async event=>{const items=event.cartData?.items||[];await handleCartUpdate(items)}); 2//# sourceMappingURL=/cdn/shop/t/404/assets/free-gift-interceptor.js.map?v=132346154882442364941786440703
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.