1class ProductForm extends HTMLElement{constructor(){super(),this.formId=`ProductForm-${this.getAttribute("data-section-id")}`,this.form=this.querySelector(`#${this.formId}`),this.formDataObject={},this.previousFormDataObject={},this.packSelectionComponent=document.querySelector("pack-selection-component"),this.productVariantDescriptions=document.querySelector(".product__variants_description"),this.productDataEl=document.querySelector('[id^="ProductJson-"]'),setTimeout(()=>{const _form_change_event=new Event("change",{bubbles:!0});this.form.dispatchEvent(_form_change_event)})}connectedCallback(){this.form.querySelectorAll(".product__variant_id").forEach(variantInput=>{variantInput.addEventListener("change",()=>{document.querySelector("pack-selection-component")&&document.querySelector("pack-selection-component").reset()})}),this.form.addEventListener("change",()=>{this.previousFormDataObject=this.formDataObject;const formData=new FormData(this.form);this.formDataObject={},formData.forEach((value,key)=>this.formDataObject[key]=key in this.formDataObject?[].concat(this.formDataObject[key],value):value),updateVariantUrl(this.formDataObject.id);const gallery=document.querySelector(`media-gallery[data-product-id="${this.formDataObject["product-id"]}"]`);gallery&&gallery.setActiveGroup(this.formDataObject.id),this.productVariantDescriptions&&(this.productVariantDescriptions.querySelectorAll(".product__variant_description").forEach(variantDescription=>variantDescription.classList.add("hidden")),this.productVariantDescriptions.querySelector(`.product__variant_description__${this.formDataObject.id}`)&&this.productVariantDescriptions.querySelector(`.product__variant_description__${this.formDataObject.id}
1`).classList.remove("hidden"));try{const selectedVariants=[],selectedPack=this.packSelectionComponent?this.packSelectionComponent.selectedPack:0,currentProduct=JSON.parse(this.productDataEl.textContent);this.packSelectionComponent.querySelectorAll(".product-slot-item").forEach(item=>{const variant=currentProduct.variants.filter(_variant=>_variant.id===Number(item.dataset.id)).reduce(t=>t);selectedVariants.push(variant)});let totalPrice=selectedVariants.reduce((sum,item)=>sum+item.price,0);const originalPrice=totalPrice;selectedVariants.length===2&&(totalPrice=totalPrice-totalPrice*.1),selectedVariants.length===3&&(totalPrice=totalPrice-totalPrice*.15);let subscriptionTotalPrice=totalPrice-totalPrice*.1,subscriptionTotalPriceFormatted=Shopify.formatMoney(subscriptionTotalPrice);const totalPriceFormatted=Shopify.formatMoney(totalPrice),originalPriceFormatted=Shopify.formatMoney(originalPrice);selectedVariants.length>=2?(this.form.querySelector(".__product_final_price_one_time").innerText=totalPriceFormatted,this.form.querySelector(".__product_original_price_one_time").innerText=originalPriceFormatted,this.form.querySelector(".__product_original_price_one_time").classList.remove("hidden")):(this.form.querySelector(".__product_final_price_one_time").innerText=originalPriceFormatted,this.form.querySelector(".__product_original_price_one_time").innerText="",this.form.querySelector(".__product_original_price_one_time").classList.add("hidden")),this.form.querySelector(".__product_original_price_subscription").innerText=totalPriceFormatted,this.form.querySelector(".__product_finale_price_subscription").innerText=subscriptionTotalPriceFormatted}catch(error){console.warn(error)}}),this.form.addEventListener("submit",async event=>{event.preventDefault();const selectedPack=this.packSelectionComponent?this.packSelectionComponent.selectedPack:0,data=this.formDataObject;if(selectedPack>1){const selectedProducts=[];if(this.packSelectionComponent.querySelectorAll(".product-slot-item").forEach(item=>{const _item={id:Number(item.dataset.id),qty:1,properties:{"Pack Size":selectedPack}};data.selling_plan_option==="subscribe"&&(_item.selling_plan=data.selling_plan),selectedProducts.push(_item)}),selectedProducts.length<selectedPack)return;this.form.classList.add("loading");const cartAddRequest=await fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:selectedProducts,sections:"cart-drawer"})}).then(res=>res.json());this.form.classList.remove("loading");const html=cartAddRequest.sections["cart-drawer"],doc=new DOMParser().parseFromString(html,"text/html");document.querySelector("cart-drawer").replaceWith(doc.querySelector("cart-drawer")),document.querySelector("cart-drawer").openDrawer()}else{this.form.classList.add("loading"),data.sections="cart-drawer";const cartAddRequest=await fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(data)}).then(res=>res.json());this.form.classList.remove("loading");const html=cartAddRequest.sections["cart-drawer"],doc=new DOMParser().parseFromString(html,"text/html");document.querySelector("cart-drawer").replaceWith(doc.querySelector("cart-drawer")),document.querySelector("cart-drawer").openDrawer()}return document.dispatchEvent(new Event("cart-update",{bubbles:!0}))})}}customElements.define("product-form-component",ProductForm);class QuickProductForm extends HTMLElement{constructor(){super(),this.form=this.querySelector("form"),this.submitButton=this.querySelector(".submit-form"),this.formObject={}}connectedCallback(){this.form.addEventListener("submit",async $event=>{if($event.preventDefault(),$event.stopPropagation(),this.form.classList.contains("loading"))return;this.form.classList.add("loading");const data={};new FormData(this.form).forEach((value,key)=>{this.formObject[key]=value}),data.id=this.formObject.id,data.quantity=this.formObject.quantity,this.formObject.subscription==="subscription"&&(data.selling_plan=this.formObject.frequency),data.sections="cart-drawer";const cartAddRequest=await fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(data)}).then(res=>res.json());this.form.classList.remove("loading");const html=cartAddRequest.sections["cart-drawer"],doc=new DOMParser().parseFromString(html,"text/html");if(document.querySelector("cart-drawer").replaceWith(doc.querySelector("cart-drawer")),document.querySelector("cart-drawer").openDrawer(),document.querySelector("cart-drawer"))return document.querySelector("cart-drawer").open(),document.dispatchEvent(new Event("cart-update",{bubbles:!0}))}),this.form.addEventListener("change",$event=>{new FormData(this.form).forEach((value,key)=>
1{this.formObject[key]=value}),this.formObject.subscription==="subscription"&&(this.submitButton.querySelector(".one-time-price").classList.add("hidden"),this.submitButton.querySelector(".subscription-price").classList.remove("hidden")),this.formObject.subscription==="one-time-purchase"&&(this.submitButton.querySelector(".one-time-price").classList.remove("hidden"),this.submitButton.querySelector(".subscription-price").classList.add("hidden")),console.log("Changed the form")})}}customElements.define("product-form",QuickProductForm); 2//# sourceMappingURL=/cdn/shop/t/331/assets/product-form.js.map?v=77354494348473483111775673975
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.