1(function(){if(window.__cartGiftReconcilerLoaded)return;window.__cartGiftReconcilerLoaded=!0;let reconciling=!1,lastCart=null;const routes=()=>window.FoxTheme.routes,pubsub=()=>window.FoxTheme.pubsub;function postUpdate(updates){const sections=[];return document.documentElement.dispatchEvent(new CustomEvent("cart:grouped-sections",{bubbles:!0,detail:{sections}})),fetch(`${routes().cart_update_url}`,{...window.FoxTheme.utils.fetchConfig(),body:JSON.stringify({updates,sections,sections_url:window.location.pathname})}).then(response=>response.json())}function publishCart(cart,extra){pubsub().publish(pubsub().PUB_SUB_EVENTS.cartUpdate,Object.assign({cart},extra||{}))}function bundleUpdatesForMainChange(items,changedMain,newMainQty){const bundleId=changedMain.properties._bundle_id;let otherMainQty=0;items.forEach(item=>{const p=item.properties||{};p._bundle_item==="main"&&p._bundle_id===bundleId&&item.key!==changedMain.key&&(otherMainQty+=item.quantity)});const previousCeiling=otherMainQty+changedMain.quantity,newCeiling=otherMainQty+newMainQty,updates={};return updates[changedMain.key]=newMainQty,items.forEach(item=>{const p=item.properties||{};p._bundle_item!=="individual"||p._bundle_id!==bundleId||(item.quantity===previousCeiling||item.quantity>newCeiling)&&(updates[item.key]=newCeiling)}),updates}function patchCartItems(){const CartItems=window.customElements&&customElements.get("cart-items");if(!CartItems||CartItems.prototype.__giftBundlePatched)return;CartItems.prototype.__giftBundlePatched=!0;const original=CartItems.prototype.updateQuantity;CartItems.prototype.updateQuantity=function(line,quantity,name,target){const run=()=>{const items=lastCart&&lastCart.items||[],changed=items[Number(line)-1];if(!changed)return original.call(this,line,quantity,name,target);const props=changed.properties||{},newQty=Number(quantity),isHero=props._bundle_item==="main"&&props._bundle_id!=null&&props._bundle_id!=="",updates=isHero?bundleUpdatesForMainChange(items,changed,newQty):{[changed.key]:newQty},addonApi=window.CartAddonReconciler,addonUpdates=addonApi?addonApi.orphanAddonUpdates(items,updates):{};if(Object.assign(updates,addonUpdates),!isHero&&Object.keys(addonUpdates).length===0)return original.call(this,line,quantity,name,target);this.showLoader(line),reconciling=!0,postUpdate(updates).then(cart=>publishCart(cart,{sources:"cart-items",target,line,name})).catch(error=>console.error("[free-gift] bundle update failed",error)).finally(()=>{reconciling=!1})};if(lastCart)return run.call(this);fetch(`${routes().cart_url}`,{...window.FoxTheme.utils.fetchConfig("json","GET")}).then(r=>r.json()).then(cart=>{lastCart=cart,run.call(this)}).catch(()=>original.call(this,line,quantity,name,target))}}function reconcile(payload){if(payload&&payload.cart&&(lastCart=payload.cart),reconciling)return;const items=lastCart&&lastCart.items||[],mainQtyByBundle={},giftLines=[];items.forEach(item=>{const p=item.properties||{};!p._bundle_item||p._bundle_id==null||p._bundle_id===""||(p._bundle_item==="main"?mainQtyByBundle[p._bundle_id]=(mainQtyByBundle[p._bundle_id]||0)+item.quantity:p._bundle_item==="individual"&&giftLines.push({key:item.key,quantity:item.quantity,bundleId:p._bundle_id}))});const updates={};giftLines.forEach(gift=>{const ceiling=mainQtyByBundle[gift.bundleId]||0;gift.quantity>ceiling&&(updates[gift.key]=ceiling)}),Object.keys(updates).length!==0&&(reconciling=!0,postUpdate(updates).then(cart=>publishCart(cart)).catch(error=>console.error("[free-gift] reconcile failed",error)).finally(()=>{reconciling=!1}))}function seedCart(){fetch(`${routes().cart_url}`,{...window.FoxTheme.utils.fetchConfig("json","GET")}).then(r=>r.json()).then(cart=>{lastCart=cart}).catch(()=>{})}function init(){return!window.FoxTheme||!window.FoxTheme.pubsub?!1:(pubsub().subscribe(pubsub().PUB_SUB_EVENTS.cartUpdate,reconcile),patchCartItems(),seedCart(),!0)}init()||document.addEventListener("DOMContentLoaded",init)})(); 2//# sourceMappingURL=/cdn/shop/t/86/assets/cart-gift-reconciler.js.map?v=56450714463518983791790053561
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.