- Created a new template for the cart rule form with custom label, switch, and choice widgets. - Implemented the InPost Pay block in the order details template for displaying delivery method, APM, and VAT invoice request. - Added legacy support for the order details template to maintain compatibility with older PrestaShop versions.
3 lines
13 KiB
JavaScript
3 lines
13 KiB
JavaScript
(()=>{(()=>{"use strict";var de={},Y=Object.defineProperty,g=Object.getOwnPropertySymbols,Z=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable,O=(e,n,t)=>n in e?Y(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,S=(e,n)=>{for(var t in n||(n={}))Z.call(n,t)&&O(e,t,n[t]);if(g)for(var t of g(n))tt.call(n,t)&&O(e,t,n[t]);return e};const I={productPageForm:"#add-to-cart-or-refresh",inpostIziButton:"inpost-izi-button",inpostIziProductButtonWrapper:".js-inpost-izi-product-btn-wrapper",inpostIziAddToCartAlert:".js-inpost-izi-add-to-cart-alert"},l=()=>typeof window.inpost_izi_selectors_map!="undefined"?S(S({},I),window.inpost_izi_selectors_map):I,et=e=>{const{inpostIziButton:n}=l();document.querySelectorAll(n).forEach(r=>{r.setAttribute("count",e)})},R={cartBound:!1},H=()=>({getCartBound:()=>R.cartBound,setCartBound:t=>{R.cartBound=t}}),p={basketDeleteBinding:"inpost/v1/izi/merchant/basket/delete/binding",basketPostBinding:"inpost/v1/izi/merchant/basket/post/binding",basketConfirmation:"inpost/v1/izi/merchant/basket/confirmation",orderComplete:"inpost/v1/izi/merchant/order/confirmation/get",basketGetLink:"inpost/v1/izi/merchant/basket/get/link",widgetGet:"inpost/v1/izi/merchant/widget/get"},C=new Map,T=()=>({getEvent:r=>C.get(r),setEvent:(r,s)=>{C.set(r,s)},removeEvent:r=>{C.delete(r)}}),w=()=>{const{orderComplete:e,basketConfirmation:n}=p,{getEvent:t,removeEvent:r}=T(),s=t(e),a=t(n);s&&(s.close(),r(e)),a&&(a.close(),r(n))},k=e=>{const{setCartBound:n,getCartBound:t}=H(),{detail:r=null}=e;r!=null&&r.masked_phone_number||r!=null&&r.basket_linked?n(!0):(r==null?void 0:r.basketLinked)===!1&&n(!1),t()||w()},A=()=>{document.querySelectorAll("inpost-izi-button").forEach(n=>{n.removeEventListener("izi-binding-complete",k),n.addEventListener("izi-binding-complete",k)})},q=()=>{setTimeout(()=>{typeof window.handleInpostIziButtons=="function"&&window.handleInpostIziButtons(),A()},10)},nt=()=>{document.querySelector(".js-cart")!==null&&q()},D=(e=0)=>{const{inpostIziButton:n}=l(),t=new CustomEvent("inpost-update-count",{detail:e});document.querySelectorAll(n).forEach(s=>{s.dispatchEvent(t)})},ot=window.inpostizi_backend_ajax_url,rt=window.inpostizi_cart_ajax_url,G=()=>ot,st=()=>rt,it=e=>e&&typeof e=="object"&&e.constructor===Object,L=e=>{let n=JSON.parse(e);return typeof n=="string"&&(n=L(n)),n},B=L,z=e=>{const n=new URL(e),t=(a,d)=>{n.searchParams.set(a,d)};return{getURL:()=>n.toString(),addParam:t,addParams:a=>{Object.keys(a).forEach(i=>{t(i,a[i])})}}},_=()=>{const e=(window==null?void 0:window.inpostizi_generic_http_error)||"Something went wrong. Please try again later.";return new Error(e)};var at=Object.defineProperty,dt=Object.defineProperties,ct=Object.getOwnPropertyDescriptors,U=Object.getOwnPropertySymbols,ut=Object.prototype.hasOwnProperty,lt=Object.prototype.propertyIsEnumerable,j=(e,n,t)=>n in e?at(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,E=(e,n)=>{for(var t in n||(n={}))ut.call(n,t)&&j(e,t,n[t]);if(U)for(var t of U(n))lt.call(n,t)&&j(e,t,n[t]);return e},M=(e,n)=>dt(e,ct(n)),N=(e,n,t)=>new Promise((r,s)=>{var a=o=>{try{i(t.next(o))}catch(c){s(c)}},d=o=>{try{i(t.throw(o))}catch(c){s(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(a,d);i((t=t.apply(e,n)).next())});const b=(e,n,t=null,r={})=>{let s={};const{addParam:a,addParams:d,getURL:i}=z(e),o={method:n,headers:E({"Content-Type":"application/json"},r)};t!==null&&(o.body=JSON.stringify(t));const c=()=>o;return{getResponse:()=>N(void 0,null,function*(){return new Promise((f,m)=>N(void 0,null,function*(){try{const v=c(),Q=i();let h=yield fetch(Q,v);if(h.status===405&&["DELETE","PUT"].includes(v.method)&&(h=yield fetch(Q,M(E({},v),{method:"POST",headers:M(E({},v.headers),{"X-HTTP-Method-Override":v.method})}))),h.status===204){f();return}let u=yield h.json();!it(u)&&typeof u=="string"&&(u=B(u)),h.ok?f(u):u!=null&&u.message?m(new Error(u.message)):m(_())}catch(v){if(v instanceof DOMException)return;m(_())}}))}),setParams:f=>{d(f)},setParam:(f,m)=>{a(f,m)}}};var pt=(e,n,t)=>new Promise((r,s)=>{var a=o=>{try{i(t.next(o))}catch(c){s(c)}},d=o=>{try{i(t.throw(o))}catch(c){s(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(a,d);i((t=t.apply(e,n)).next())});const vt=()=>pt(void 0,null,function*(){const{getResponse:e}=b(st(),"GET");return yield e()});var ft=(e,n,t)=>new Promise((r,s)=>{var a=o=>{try{i(t.next(o))}catch(c){s(c)}},d=o=>{try{i(t.throw(o))}catch(c){s(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(a,d);i((t=t.apply(e,n)).next())});const mt=e=>ft(void 0,null,function*(){var n,t,r,s;let a=((t=(n=e==null?void 0:e.resp)==null?void 0:n.cart)==null?void 0:t.products_count)||null;if(a===null&&(a=((s=(r=window.prestashop)==null?void 0:r.cart)==null?void 0:s.products_count)||null),typeof a=="number")D(a);else try{const{count:d=null}=yield vt();typeof d=="number"&&D(d)}catch(d){console.error(d)}}),$=e=>new DOMParser().parseFromString(e,"text/html").body.children[0],ht=e=>{const{inpostIziProductButtonWrapper:n}=l(),r=$(e).querySelector(n),s=document.querySelector(`${n}[data-hook="displayProductActions"]`);r&&s&&s.replaceWith(r)},wt=e=>{const n=e==null?void 0:e.product_add_to_cart;n&&ht(n),q()},_t=()=>{setTimeout(()=>{const e=document.querySelector(".inpostizi-modal");e&&e.remove()},1)},yt=e=>{_t();const{getCartBound:n}=H();setTimeout(()=>{n()||w()},50)},{getEvent:Pt,setEvent:Ct,removeEvent:Bt}=T(),F=(e,n,t=()=>{})=>{const r=()=>{const{addParam:d,getURL:i}=z(G());return d("path",e),i()},s=()=>{const d=Pt(e);d&&(d.close(),Bt(e))};return{close:s,open:()=>{const d=new EventSource(r()),i=()=>{s(),Ct(e,d),d.removeEventListener("open",i)};d.addEventListener("open",i),d.addEventListener("message",n),d.addEventListener("error",t)}}};function zt(){return new Promise((e,n)=>{const t=d=>{const{data:i=null}=d;if(i){let o;try{o=B(i)}catch(c){return}o!=null&&o.phone_number&&(e(o),a())}},r=d=>{d.target.readyState!==EventSource.CONNECTING&&(n(_()),a())},{open:s,close:a}=F(p.basketConfirmation,t,r);s()})}const W=zt;function Et(){return new Promise((e,n)=>{const t=a=>{const{data:d=null}=a;if(d){let i,o;try{i=B(d)}catch(c){return}if((i==null?void 0:i.action)==="redirect"&&(i!=null&&i.url))o={action:"redirect",redirect:i.url};else if(((i==null?void 0:i.action)==="delete"||(i==null?void 0:i.action)==="refresh")&&(o={action:"refresh"},(i==null?void 0:i.action)==="refresh")){prestashop.emit("updateCart",{reason:{linkAction:"refresh"},resp:{}});return}o&&e(o)}},r=a=>{a.target.readyState!==EventSource.CONNECTING&&(n(_()),close())},{open:s}=F(p.orderComplete,t,r);s()})}const x=Et;var bt=(e,n,t)=>new Promise((r,s)=>{var a=o=>{try{i(t.next(o))}catch(c){s(c)}},d=o=>{try{i(t.throw(o))}catch(c){s(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(a,d);i((t=t.apply(e,n)).next())});const gt=()=>new Promise((e,n)=>{setTimeout(()=>{n()},1e3),W().then(t=>{e(t)}).catch(()=>{n()})}),Ot=()=>bt(void 0,null,function*(){let e=null;try{e=yield gt()}catch(n){w();return}if(e!=null&&e.inpost_basket_id&&(e==null?void 0:e.status)==="SUCCESS"){const n=yield x();(n==null?void 0:n.action)==="redirect"&&n.redirect?window.location.href=n.redirect:(n==null?void 0:n.action)==="refresh"&&(window.location=window.location.href)}}),y=(e,n,t=null,r={})=>{const{addParam:s,getURL:a}=z(G());return s("path",e),b(a(),n,t,r)};var St=(e,n,t)=>new Promise((r,s)=>{var a=o=>{try{i(t.next(o))}catch(c){s(c)}},d=o=>{try{i(t.throw(o))}catch(c){s(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(a,d);i((t=t.apply(e,n)).next())});const It=(e,n)=>{const{widgetGet:t}=p;return`${t}/${e}/${n}`},Rt=(e,n)=>St(void 0,null,function*(){const t=It(e,n),{getResponse:r,setParam:s}=y(t,"GET");return yield r()});var Ht=(e,n,t)=>new Promise((r,s)=>{var a=o=>{try{i(t.next(o))}catch(c){s(c)}},d=o=>{try{i(t.throw(o))}catch(c){s(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(a,d);i((t=t.apply(e,n)).next())});const Tt=(e,n,t)=>Ht(void 0,null,function*(){var r;const{content:s=null}=yield Rt(n,t),{inpostIziButton:a}=l();s&&((r=e.querySelector(a))==null||r.remove(),e.prepend($(s)),typeof window.handleInpostIziButtons=="function"&&window.handleInpostIziButtons())}),kt=()=>{const e=()=>{prestashop.on("updateCart",mt),prestashop.on("updatedCart",nt),prestashop.on("updatedProduct",wt),document.addEventListener("iziModalEventClose",yt),window.addEventListener("beforeunload",w),A()},n=()=>{document.querySelectorAll(l().inpostIziProductButtonWrapper).forEach(s=>{if(s.getAttribute("data-refresh")!=="true")return;const a=parseInt(s.getAttribute("data-id-product"),10),d=s.getAttribute("data-hook");Tt(s,d,a)})};return{init:()=>{var r;(r=prestashop==null?void 0:prestashop.cart)!=null&&r.products_count&&et(prestashop.cart.products_count),Ot(),e(),n()}}},At=(e,n="success",t="")=>{const r=document.createElement("div");return r.classList.add("alert",`alert-${n}`),typeof t=="string"?r.classList.add(t):Array.isArray(t)&&t.forEach(s=>{r.classList.add(s)}),r.textContent=e,r};var qt=(e,n,t)=>new Promise((r,s)=>{var a=o=>{try{i(t.next(o))}catch(c){s(c)}},d=o=>{try{i(t.throw(o))}catch(c){s(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(a,d);i((t=t.apply(e,n)).next())});const Dt=e=>{const{inpostIziProductButtonWrapper:n,inpostIziAddToCartAlert:t}=l(),r=At(e.message,"danger",t.replace(".","")),s=document.querySelector(n);if(s){const a=s.querySelector(t);a&&a.remove(),s.prepend(r)}},Gt=e=>qt(void 0,null,function*(){const{getResponse:n,setParams:t}=b(prestashop.urls.pages.cart,"POST",null,{"X-Requested-With":"XMLHttpRequest","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"});t(e);const r=yield n();if(r!=null&&r.hasError&&(r!=null&&r.errors)&&Array.isArray(r.errors)){const s=new Error(r.errors.join(`
|
|
`));throw setTimeout(()=>{Dt(s),typeof window.handleInpostIziButtons=="function"&&window.handleInpostIziButtons()}),s}prestashop.emit("updateCart",{reason:{idProduct:r.id_product,idProductAttribute:r.id_product_attribute},resp:r})});var Lt=Object.defineProperty,P=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,V=(e,n,t)=>n in e?Lt(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,Ut=(e,n)=>{for(var t in n||(n={}))J.call(n,t)&&V(e,t,n[t]);if(P)for(var t of P(n))X.call(n,t)&&V(e,t,n[t]);return e},jt=(e,n)=>{var t={};for(var r in e)J.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&P)for(var r of P(e))n.indexOf(r)<0&&X.call(e,r)&&(t[r]=e[r]);return t},Mt=(e,n,t)=>new Promise((r,s)=>{var a=o=>{try{i(t.next(o))}catch(c){s(c)}},d=o=>{try{i(t.throw(o))}catch(c){s(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(a,d);i((t=t.apply(e,n)).next())});const Nt=e=>{const n=new FormData(e),t={},r=[];for(let[s,a]of n.entries())name.indexOf("group")===0?r.push({name,value:encodeURIComponent(a)}):t[s]=a;return t.group=r,t};function $t(e){return Mt(this,null,function*(){const{productPageForm:n}=l(),t=document.querySelector(n);if(!t){console.warn("Error while adding product to cart: product not found.");return}const r=Nt(t),{group:s}=r,a=jt(r,["group"]),d=Ut({add:1,action:"update",ajax:1},a);return s.forEach(i=>{d[i.name]=i.value}),yield Gt(d)})}const Ft=$t;var Wt=(e,n,t)=>new Promise((r,s)=>{var a=o=>{try{i(t.next(o))}catch(c){s(c)}},d=o=>{try{i(t.throw(o))}catch(c){s(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(a,d);i((t=t.apply(e,n)).next())});function xt(){return Wt(this,null,function*(){const{getResponse:e}=y(p.basketDeleteBinding,"DELETE");return yield e()})}const Jt=xt,Xt=e=>(window==null?void 0:window.inpostizi_product_page_id_product)===e;function Vt(e){if(!e)return!0;const n=parseInt(e,10);if(Xt(n))return!0;const t=`inpost-izi-button[product-id="${n}"][baskedlinked="true"]`;return document.querySelector(t),!1}const Kt=Vt;var Qt=(e,n,t)=>new Promise((r,s)=>{var a=o=>{try{i(t.next(o))}catch(c){s(c)}},d=o=>{try{i(t.throw(o))}catch(c){s(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(a,d);i((t=t.apply(e,n)).next())});const Yt=(e,n)=>{const{basketPostBinding:t}=p;if(!e&&!n)return t;if(e&&n)return`${t}/${e}/${n}`},K=(e,n,t)=>Qt(void 0,null,function*(){const r=Yt(e,n),{getResponse:s,setParam:a}=y(r,"POST");return a("browser",window.iziGetBrowserData({base64:!0})),a("binding_place",t),yield s()});var Zt=(e,n,t)=>new Promise((r,s)=>{var a=o=>{try{i(t.next(o))}catch(c){s(c)}},d=o=>{try{i(t.throw(o))}catch(c){s(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(a,d);i((t=t.apply(e,n)).next())});function te(e,n="",t="",r="PRODUCT_CARD"){return Zt(this,null,function*(){return yield K(n,t,r)})}const ee=te;var ne=(e,n,t)=>new Promise((r,s)=>{var a=o=>{try{i(t.next(o))}catch(c){s(c)}},d=o=>{try{i(t.throw(o))}catch(c){s(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(a,d);i((t=t.apply(e,n)).next())});function oe(e="",n="",t="PRODUCT_CARD"){return ne(this,null,function*(){return yield K(e,n,t)})}const re=oe;var se=(e,n,t)=>new Promise((r,s)=>{var a=o=>{try{i(t.next(o))}catch(c){s(c)}},d=o=>{try{i(t.throw(o))}catch(c){s(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(a,d);i((t=t.apply(e,n)).next())});function ie(){return se(this,null,function*(){const{getResponse:e}=y(p.basketGetLink,"GET");return yield e()})}const ae=ie;window.iziAddToCart=Ft,window.iziBindingDelete=Jt,window.iziCanBeBound=Kt,window.iziGetBindingData=ee,window.iziGetIsBound=W,window.iziGetOrderComplete=x,window.iziGetPayData=re,window.iziMobileLink=ae,document.addEventListener("DOMContentLoaded",()=>{kt().init()})})();})();
|