1class GWP{constructor(){this.giftVariantId=window.gwpGiftVariantId??null,this.threshold=window.gwpThreshold??null,this.cartElement=null,this.renderCart=!1}init(){this.giftVariantId&&this.threshold&&(this.cartElement=document.querySelector("cart-notification")||document.querySelector("cart-drawer"),this.renderCart=this.cartElement&&"function"==typeof this.cartElement.renderContents&&!document.querySelector("body").classList.contains("template--cart"),this.processCart(),this.bindEvents())}bindEvents(){document.addEventListener("cart:updated",t=>{this.processCart()})}processCart(e=null){let r=this;if(e&&e.hasOwnProperty("items")){var n=e.items?.find(t=>t.id==this.giftVariantId&&t.properties.hasOwnProperty("_gwp_gift"));let t=e.total_price>=this.threshold;void 0!==n&&n.hasOwnProperty("final_line_price")&&(t=e.total_price-n.final_line_price>=this.threshold),void 0===n&&t?this.addGiftToCart().then(t=>console.log("response",t)):void 0===n||t||this.removeGiftFromCart(n).then(t=>console.log("response",t))}else this.getCart().then(t=>{r.processCart(t.cart)})}addGiftToCart(){let e=this,t=null;"function"==typeof this.cartElement.getSectionsToRender&&(t={sections:this.cartElement.getSectionsToRender().map(t=>t.section)}),this.addToCart({id:this.giftVariantId,quantity:1,properties:{_gwp_gift:"true"}},null,t).then(t=>{e.renderCart?e.cartElement.renderContents(t.cart):(console.log("Cart element not found or renderContents not available, reloading page"),location.reload())},t=>{console.log("error",t)})}getCart(){return new Promise(async(t,e)=>{var r=await fetch(window.Shopify.routes.root+"cart.js",{method:"GET",headers:{"Content-Type":"application/json"}});r.ok?t({cart:await r.json()}):e({status:r.status,message:r.statusText})})}removeGiftFromCart(t){let e=this;t={id:t.key,quantity:0};let r=null;"function"==typeof this.cartElement.getSectionsToRender&&(r={sections:this.cartElement.getSectionsToRender().map(t=>t.section)}),fetch(window.Shopify.routes.root+"cart/change.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...t,...r})}).then(t=>t.json()).then(t=>(e.renderCart?e.cartElement.renderContents(t):(console.log("Cart element not found or renderContents not available, reloading page"),location.reload()),t)).catch(t=>{console.error("Error:",t)})}addToCart(n,o={},a={}){return new Promise(async(t,e)=>{var r=await fetch(window.Shopify.routes.root+"cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...n,...o,...a})});r.ok?t({status:200,message:"Item added to cart.",cart:await r.json()}):e({status:r.status,message:r.statusText,variant_id:n.id})})}}let gwp=new GWP;gwp.init(); 2//# sourceMappingURL=gwp.min.js.map
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.