1class CartHandler{constructor(initialCart={},initialCartMetaData2={}){this.cart=initialCart,this.cartMetaData=initialCartMetaData2,this.cartEl=document.querySelector("cart-notification")||document.querySelector("cart-drawer"),this.freeGiftVariantId=31874798878801,this.initializeSubscriptions=this.initializeSubscriptions.bind(this),this.initializeSubscriptions()}initializeSubscriptions(){this.cartUpdateUnsubscriber=subscribe(PUB_SUB_EVENTS.cartUpdate,async event=>{try{const response=await fetch(window.routes.cart_url+"?view=metafields");if(!response.ok)throw new Error(`Network response was not ok: ${response.status} ${response.statusText}`);const cartData=await response.json();this.cart=cartData.cart;const metafieldsData=cartData.metafields;this.handleEnrichedCartData(metafieldsData)}catch(error){console.error("Error fetching cart metafields:",error);const errorElement=document.querySelector("#error-message");errorElement&&(errorElement.textContent="Failed to update cart information. Please try again.")}})}handleEnrichedCartData(enrichedCartData){this.cartMetaData=enrichedCartData;const clubProductId=7232894435409,eligibleTags=["Club Discount Eligible"],productTags=["beer","seltzer","bundle"],isClubProductInCart=this.cart.items.some(item=>item.product_id===clubProductId),clubProductsInCart=this.cart.items.filter(item=>{const itemMetafields=this.cartMetaData.find(meta=>meta.key===item.key);if(itemMetafields?.tags){const tags=itemMetafields.tags;return eligibleTags.some(tag=>tags.includes(tag))&&productTags.some(tag=>tags.includes(tag))}return!1}),clubProductsInCartCount=clubProductsInCart.reduce((acc,item)=>{const itemMetafields=this.cartMetaData.find(meta=>meta.key===item.key);return itemMetafields?.tags.includes("bundle")?acc+itemMetafields.bundle_size*item.quantity:acc+item.quantity},0),freeGlass=this.cart.items.find(item=>item.properties?.__free_gift&&item.properties?.__trigger==="new_club_membership");isClubProductInCart&&clubProductsInCartCount>=4&&!freeGlass&&this.addFreeGiftToCart(),clubProductsInCartCount<4&&freeGlass&&this.removeFreeGiftFromCart(freeGlass.key),!isClubProductInCart&&freeGlass&&this.removeFreeGiftFromCart(freeGlass.key),window.__abc=window.__abc||{};const ShopifyCartData={cart:this.cart,cartMetaFields:this.cartMetaData,clubProductsInCartCount,clubProductsInCart,isClubProductInCart};window.__abc.ShopifyCartData=ShopifyCartData,window.dispatchEvent(new CustomEvent("cartUpdateEnriched",{detail:ShopifyCartData,bubbles:!0,composed:!0}))}cleanup(){this.cartUpdateUnsubscriber&&this.cartUpdateUnsubscriber()}removeFreeGiftFromCart(freeGiftItemKey){fetch("/cart/change.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:freeGiftItemKey,quantity:0})}).then(response=>response.json()).then(cart=>{this.cart=cart,publish(PUB_SUB_EVENTS.cartUpdate,{source:"CartHandler",cartData:cart})}).catch(error=>console.error("Error removing free gift:",error))}addFreeGiftToCart(){const FREE_GIFT_VARIANT_ID=this.freeGiftVariantId,toSend={};toSend.items=[{id:FREE_GIFT_VARIANT_ID,quantity:1,properties:{__free_gift:!0,__promo:"New Club Membership",__trigger:"new_club_membership"}}],toSend.sections=this.cartEl.getSectionsToRender().map(section=>section.id);const config=fetchConfig("javascript");config.headers["X-Requested-With"]="XMLHttpRequest",delete config.headers["Content-Type"],config.headers["Content-Type"]="application/json",config.body=JSON.stringify(toSend),fetch(`${routes.cart_add_url}`,config).then(response=>response.json()).then(response=>{if(response.status){console.error("Error adding free gift:",response);return}this.cart=response,this.cartEl.renderContents(response)}).catch(error=>console.error("Error adding free gift:",error))}}const initialCartData=window.__abc.ShopifyCartData.cart||{},initialCartMetaData=window.__abc.ShopifyCartData.cartMetaFields||{},cartHandler=new CartHandler(initialCartData,initialCartMetaData);window.addEventListener("beforeunload",()=>{cartHandler.cleanup()});class ConfirmRemovalModal extends ModalDialog{constructor(){super()}handleConfirm(event){const itemKey=event.target.getAttribute("data-item-key");itemKey&&this.removeItemFromCart(itemKey)}handleCancel(){this.hide()}removeItemFromCart(itemKey){fetch("/cart/change.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:itemKey,quantity:0})}).then(response=>response.json()).then(cart=>{this.hide(),location.reload()}).catch(error=>{console.error("Error removing item from cart:",error),this.hide()})}}customElements.define("confirm-removal-modal",ConfirmRemovalModal); 2//# sourceMappingURL=/cdn/shop/t/299/assets/cart-handler.js.map?v=88458828715904327761768413621
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.