PageSourceSearch

https://www.olakala.de/cdn/shop/t/83/assets/snippets_util-product-form.js?v=74882440908572316541770043869

js olakala.de collected 2026-09-24 18:10:52 UTC 4,331 bytes, 1 lines download raw bytes

1import{a as O,b as S,c as y,d as _,f as D,g as I,h as M,j as q,k as g,m as b,n as B}from"./chunk-KQAAPGAY.js";import{c as i,d as f}from"./chunk-WRTBYHPH.js";var n=class extends q{get duplicateSizeModal(){return document.querySelector("util-duplicate-size-modal")}get form(){return this.querySelector(`#${this.formId}`)}get formData(){return new FormData(this.form)}get formObj(){return Object.fromEntries(this.formData)}get currentVariant(){let t=this.formObj;return this.variants.find(e=>e.option1==t.option1&&e.option2==t.option2&&e.option3==t.option3)}checkForDuplicateSize(){return f(this,null,function*(){var m,h;console.log("checkForDuplicateSize",this.currentVariant);let t=this.currentProductId,e=yield b.Cart.fetch();console.log("Current cart:",e);let s=e.items.find(r=>{var a,d;return r.product_id===t&&r.variant_id!==((a=this.currentVariant)==null?void 0:a.id)&&((d=r.properties)==null?void 0:d._type)==null});if(e.items.find(r=>{var a,d;return r.product_id===t&&r.variant_id===((a=this.currentVariant)==null?void 0:a.id)&&((d=r.properties)==null?void 0:d._type)==null})!=null||s==null)return!1;let o=this.duplicateSizeModal;return o==null?(console.warn("Duplicate size modal not found in DOM"),!1):!(yield o.show({productTitle:s.product_title,existingVariantTitle:s.variant_title,newVariantTitle:(h=(m=this.currentVariant)==null?void 0:m.title)!=null?h:"Selected Variant"}))})}submit(t,e,s=!1){return f(this,null,function*(){var l,o,p,m,h;if(e.preventDefault(),(l=this.addToCartBtn)==null||l.setAttribute("loading",""),yield this.checkForDuplicateSize()){(o=this.addToCartBtn)==null||o.removeAttribute("loading");return}if(this.bundlesBlock!=null&&this.bundlesBlock.hasAnySelectedBundles()==!0){let r=this.bundlesBlock.getSelectedBundleItemsForCart();yield fetch(this.cartUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:r})}),b.Cart.emit("updated"),g.emit("cart:open")}else{let r=this.formData.getAll("addons").filter(u=>u!==""&&typeof u=="string"),a=this.formData,d=(m=(p=a.get("id"))==null?void 0:p.toString())!=null?m:"000";a.set("properties[_unique]",d);let T=yield fetch(this.cartUrl,{method:"POST",headers:{Accept:"application/javascript","X-Requested-With":"XMLHttpRequest"},body:a}).then(u=>f(this,null,function*(){return yield u.json()}));if(T.status===422)this.errorOutputs.forEach(u=>{u.show(T.description)});else{this.errorOutputs.forEach(c=>{c.hide()});let u=c=>c.replace(/\$\$.*$/,""),v=r.map(c=>{var w,C,V,E;return{id:parseInt(u(c)),quantity:parseInt((w=a.get("quantity"))!=null?w:"1"),properties:{_unique:d,_type:(C=a.get(`type--${c}`))!=null?C:"addon",_custom:(V=a.get(`custom--${c}`))!=null?V:"",Text:(E=a.get(`text--${c}`))!=null?E:void 0}}});v.length>0&&(yield b.Cart.addItem(...v)),b.Cart.emit("updated"),g.emit("cart:open")}}(h=this.addToCartBtn)==null||h.removeAttribute("loading")})}updateSelectedVariant(){return f(this,null,function*(){if(console.log("updateSelectedVariant"),yield B(10),this.currentVariant){this.form.elements.namedItem("id").value=this.currentVariant.id.toString();let t=new URL(window.location.href);t.searchParams.set("variant",this.currentVariant.id.toString()),window.history.replaceState(null,"",t),g.emit("product:variantChanged",this.currentVariant)}else g.emit("product:invalidCombination")})}setCurrentOptions(t,e,s){let l=this.form.elements.namedItem("option1"),o=this.form.elements.namedItem("option2"),p=this.form.elements.namedItem("option3");l&&(l.value=t!=null?t:""),o&&(o.value=e!=null?e:""),p&&(p.value=s!=null?s:""),this.form.dispatchEvent(new Event("change",{bubbles:!0}))}handleSizeTableChange(t,e){let{option1:s,option2:l,option3:o}=e.detail;this.setCurrentOptions(s,l,o),this.updateSelectedVariant()}};i([D("form_id")],n.prototype,"formId",2),i([y("routes.cart_add_url")],n.prototype,"cartUrl",2),i([y("product.id")],n.prototype,"currentProductId",2),i([y("product.variants")],n.prototype,"variants",2),i([M("[data-form-error]")],n.prototype,"errorOutputs",2),i([I("[data-add-to-cart]")],n.prototype,"addToCartBtn",2),i([I("shop-bundles")],n.prototype,"bundlesBlock",2),i([_("submit","form")],n.prototype,"submit",1),i([S("form:changeOption")],n.prototype,"updateSelectedVariant",1),i([S("sizeTable:change")],n.prototype,"handleSizeTableChange",1),n=i([O("util-product-form")],n);export{n as UtilProductForm};

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.