@ikas/storefront 5.0.71 → 5.0.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{__awaiter as t,__generator as e,__assign as n}from'./../../../ext/tslib/tslib.es6.js';import*as r from"react";import{reaction as o}from"mobx";import{listStorefrontPopup as i,SortByDirectionEnum as a}from"@ikas/storefront-api";import{IkasStorefrontConfig as u}from"@ikas/storefront-config";import{Analytics as s}from"../../../analytics/analytics.js";import"../../../analytics/head/index.js";import{IkasBaseStore as c}from"../../../store/base.js";import"../../../store/customer/index.js";import"../../../store/cart/index.js";import d from"../../../store/product/index.js";import{POPUP_CONTEXT_UPDATE_EVENT as l}from'./../../../ext/@ikas/popup-script-injector/dist/popup-script-injector.es.js';import{resolveStoreUrl as p,resolveCartUrl as f}from"./common.js";var m=function(n){return t(void 0,void 0,void 0,(function(){var r,o,i,a,l,m,I,w,S,P,y,C,k,b,j,L;return e(this,(function(E){switch(E.label){case 0:return r={popups:n,cartUrl:""},[4,function(){return new Promise((function(t){var e=setInterval((function(){var n=u.getSessionId();n&&(clearInterval(e),t(n))}),100)}))}()];case 1:return E.sent(),(o=u.getSessionId())&&(r.sessionId=o),(i=u.getCdnUrl())&&(r.cdnUrl=i),(a=null===(b=u.getMerchantSettings())||void 0===b?void 0:b.merchantId)&&(r.merchantId=a),(l=p())&&(r.storeUrl=l),(m=f())&&(r.cartUrl=m),(I=u.getCustomerToken())&&(r.customerToken=I),(w=u.getCurrentLocale())&&(r.locale=w),(S=null===(L=null===(j=u.getCurrentRouting())||void 0===j?void 0:j.countryCodes)||void 0===L?void 0:L[0])&&(r.countryCode=S),(P=u.getPriceListId())&&(r.priceListId=P),(y=u.getSalesChannelId())&&(r.salesChannelId=y),T=c.getInstance().customerStore.customer,(C=T?g(T):null)&&(r.customer=C),D=c.getInstance().cartStore.cart,(k=D?h(D):null)&&(r.cart=k),r.services=function(){var n=this,r=c.getInstance();return{searchProducts:function(r){return t(n,void 0,void 0,(function(){var t,n,o;return e(this,(function(e){switch(e.label){case 0:return[4,d.searchProducts(v(r))];case 1:return(null==(t=e.sent())?void 0:t.isSuccess)&&(null===(o=null===(n=t.data)||void 0===n?void 0:n.data)||void 0===o?void 0:o.length)?[2,t.data.data]:[2,[]]}}))}))},addItemToCart:function(o){var i=o.product,a=o.variant,u=o.quantity;return t(n,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,r.cartStore.addItem(a,i,null!=u?u:1)];case 1:return[2,{success:!!(null==(t=e.sent())?void 0:t.success)}]}}))}))},saveCustomerFormData:function(o){return t(n,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,r.customerStore.saveCustomerFormData({email:o.email,firstName:o.firstName,lastName:o.lastName,birthDate:o.birthDate||"",phone:o.phone||"",storefrontPopupId:o.popupId,subscriptions:o.subscriptions})];case 1:return t.sent(),[2]}}))}))},getLastViewedProducts:function(){return t(n,void 0,void 0,(function(){var t;return e(this,(function(e){return"function"==typeof(t=r.customerStore).getLastViewedProducts?[2,t.getLastViewedProducts()]:[2,[]]}))}))},formatVariantSellPrice:function(t){return t.formattedSellPrice||""},formatVariantDiscountPrice:function(t){return t.formattedDiscountPrice||null},hasVariantDiscount:function(t){return!!t.hasDiscount},getVariantDiscountPercentage:function(t){var e=t.discountPercentage;return null==e?null:"number"==typeof e?e.toString():e},redirectToProduct:function(t){return!!t.url&&(window.location.href=t.url,!0)},viewPopup:function(t){s.viewStorefrontPopup(t)}}}(),[2,r]}var D,T}))}))};function v(t){var e,n,r,o,i,s=null===(e=t.order)||void 0===e?void 0:e.map((function(t){return{direction:"ASC"===t.direction?a.ASC:a.DESC,type:t.type}}));return{input:{page:null!==(n=t.page)&&void 0!==n?n:1,perPage:null!==(r=t.perPage)&&void 0!==r?r:10,order:s,productIdList:t.productIdList,categoryIdList:t.categoryIdList,priceListId:null!==(o=t.priceListId)&&void 0!==o?o:u.getPriceListId(),salesChannelId:null!==(i=t.salesChannelId)&&void 0!==i?i:u.getSalesChannelId()}}}function g(t){return{email:t.email,firstName:t.firstName,lastName:t.lastName,birthDate:t.birthDate,phone:t.phone,gender:t.gender?String(t.gender):null,customerGroupIds:t.customerGroupIds||[],customerSegmentIds:t.customerSegmentIds||[],subscriptionStatus:t.subscriptionStatus?String(t.subscriptionStatus):null}}function h(t){var e,n,r=[],o=new Set,i=new Set,a=new Set,u=new Set,s=new Set,c=new Set;return t.items.forEach((function(t){var e,n,s,d=t.variant,l=(null==d?void 0:d.productId)||null,p=(null==d?void 0:d.id)||null,f=(null===(e=null==d?void 0:d.brand)||void 0===e?void 0:e.id)||null,m=(null===(n=null==d?void 0:d.categories)||void 0===n?void 0:n.map((function(t){return t.id})).filter(Boolean))||[];r.push({productId:l,variantId:p,brandId:f,categoryIds:m,quantity:t.quantity,finalPrice:t.finalPrice}),l&&o.add(l),p&&i.add(p),f&&a.add(f),m.forEach((function(t){return t&&u.add(t)})),(null===(s=t.discount)||void 0===s?void 0:s.campaignOfferId)&&c.add(t.discount.campaignOfferId)})),null===(e=t.campaignOffers)||void 0===e||e.forEach((function(t){t.campaignOfferId&&c.add(t.campaignOfferId)})),null===(n=t.orderAdjustments)||void 0===n||n.forEach((function(t){t.campaignId&&s.add(t.campaignId)})),{totalPrice:t.totalPrice,totalFinalPrice:t.totalFinalPrice,itemCount:t.itemCount,itemQuantity:t.itemQuantity,currencyCode:t.currencyCode||null,lines:r,productIds:Array.from(o),variantIds:Array.from(i),brandIds:Array.from(a),categoryIds:Array.from(u),appliedCampaignIds:Array.from(s),appliedCampaignOfferIds:Array.from(c),couponCode:t.couponCode||null}}function I(t){"undefined"!=typeof window&&(window.ikasPopupConfig&&(void 0!==t.customer&&(window.ikasPopupConfig.customer=t.customer),void 0!==t.cart&&(window.ikasPopupConfig.cart=t.cart),void 0!==t.customerToken&&(window.ikasPopupConfig.customerToken=t.customerToken||void 0)),"function"!=typeof window.updateIkasPopupContext?window.dispatchEvent(new CustomEvent(l,{detail:t})):window.updateIkasPopupContext(t))}function w(a){var s=this;a.router;var d=a.pageSpecificDataId,l=a.pageType;r.useEffect((function(){if("undefined"!=typeof window&&"undefined"!=typeof document){var r,a=!1,d=[],l=function(t,e){if(function(t){t.setAttribute("data-ikas-popup-widget","true"),!t.dataset.ikasPopupWidgetUrl&&t.src&&(t.dataset.ikasPopupWidgetUrl=t.src)}(t),"true"===t.dataset.ikasPopupWidgetLoaded)return e(),function(){};var n=function(){t.dataset.ikasPopupWidgetLoaded="true",e()},r=function(e){console.error("[@ikas/storefront] Failed to load popup widget script",t.src,e)};return t.addEventListener("load",n,{once:!0}),t.addEventListener("error",r,{once:!0}),function(){t.removeEventListener("load",n),t.removeEventListener("error",r)}},p=function(t){var e=window.location.href.includes("http://localhost:3333/")?"http://localhost:9000/popup-script-injector.iife.js":"/sf/assets/popup/popup-script-injector.iife.js";if(e){var n=function(){a||function(t){if("function"==typeof window.startIkasPopupWidget)try{window.startIkasPopupWidget(t)}catch(t){console.error("[@ikas/storefront] Failed to start popup widget",t)}}(t)},o=document.querySelector('script[data-ikas-popup-widget="true"]');if(o)r=l(o,n);else{var i=document.createElement("script");i.src=e,i.defer=!0,r=l(i,n),document.body.appendChild(i)}}},f=function(t){var e=window.location.href.includes("http://localhost:3333/")?"http://localhost:9000/style.css":"/sf/assets/popup/style.css";if(e&&!document.querySelector('link[href="'.concat(e,'"]'))){var n=document.createElement("link");n.rel="stylesheet",n.href=e,n.setAttribute("data-ikas-popup-widget","true");n.addEventListener("error",(function(t){console.error("[@ikas/storefront] Failed to load popup widget CSS",e,t)}),{once:!0}),document.head.appendChild(n)}};return t(s,void 0,void 0,(function(){var r,l,v;return e(this,(function(w){switch(w.label){case 0:return r=u.getStorefrontPopups()||[],[4,(C=r,t(s,void 0,void 0,(function(){var t,r,o,a,u;return e(this,(function(e){switch(e.label){case 0:if(!(t=C.map((function(t){return t.id})).filter(Boolean)).length)return[2,C];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,i({idList:t})];case 2:return(null==(r=e.sent())?void 0:r.isSuccess)&&(null===(u=r.data)||void 0===u?void 0:u.length)?(o=r.data,[2,C.map((function(t){var e=o.find((function(e){return e.id===t.id}));return e?n(n({},e),{isFilteredOnServerSide:t.isFilteredOnServerSide}):t}))]):[3,4];case 3:return a=e.sent(),console.error("[@ikas/storefront] Failed to fetch popup details",a),[3,4];case 4:return[2,C]}}))})))];case 1:return l=w.sent(),a?[2]:[4,m(l)];case 2:return v=w.sent(),window.ikasPopupConfig=v,p(v),f(),S=c.getInstance(),P=o((function(){var t=S.customerStore.customer;return t?{email:t.email,gender:t.gender,groupIds:(t.customerGroupIds||[]).join(","),segmentIds:(t.customerSegmentIds||[]).join(","),subscriptionStatus:t.subscriptionStatus}:null}),(function(){var t=S.customerStore.customer;I({customer:t?g(t):null,customerToken:u.getCustomerToken()||null})})),y=o((function(){var t=S.cartStore.cart;return t?{total:t.totalFinalPrice,itemCount:t.itemCount,quantity:t.itemQuantity,productSignature:t.items.map((function(t){var e,n;return"".concat((null===(e=t.variant)||void 0===e?void 0:e.productId)||"",":").concat((null===(n=t.variant)||void 0===n?void 0:n.id)||"",":").concat(t.quantity)})).join("|"),campaignSignature:(t.orderAdjustments||[]).map((function(t){return t.campaignId||""})).join("|"),couponCode:t.couponCode}:null}),(function(){var t=S.cartStore.cart;I({cart:t?h(t):null})})),d.push(P,y),[2]}var S,P,y,C}))})),function(){a=!0,null==r||r(),d.forEach((function(t){return t()})),d=[],"function"==typeof window.destroyIkasPopupWidget&&window.destroyIkasPopupWidget()}}}),[d,l])}export{w as usePopupWidget};
1
+ import{__awaiter as t,__generator as e,__assign as n}from'./../../../ext/tslib/tslib.es6.js';import*as r from"react";import{reaction as o}from"mobx";import{listStorefrontPopup as i,SortByDirectionEnum as a}from"@ikas/storefront-api";import{IkasStorefrontConfig as u}from"@ikas/storefront-config";import{Analytics as s}from"../../../analytics/analytics.js";import"../../../analytics/head/index.js";import{IkasBaseStore as c}from"../../../store/base.js";import"../../../store/customer/index.js";import"../../../store/cart/index.js";import d from"../../../store/product/index.js";import{POPUP_CONTEXT_UPDATE_EVENT as l}from'./../../../ext/@ikas/popup-script-injector/dist/popup-script-injector.es.js';import{resolveStoreUrl as p,resolveCartUrl as f}from"./common.js";var m=function(n){return t(void 0,void 0,void 0,(function(){var r,o,i,a,l,m,I,w,S,P,y,C,k,b,j,L;return e(this,(function(E){switch(E.label){case 0:return r={popups:n,cartUrl:""},[4,function(){return new Promise((function(t){var e=setInterval((function(){var n=u.getSessionId();n&&(clearInterval(e),t(n))}),100)}))}()];case 1:return E.sent(),(o=u.getSessionId())&&(r.sessionId=o),(i=u.getCdnUrl())&&(r.cdnUrl=i),(a=null===(b=u.getMerchantSettings())||void 0===b?void 0:b.merchantId)&&(r.merchantId=a),(l=p())&&(r.storeUrl=l),(m=f())&&(r.cartUrl=m),(I=u.getCustomerToken())&&(r.customerToken=I),(w=u.getCurrentLocale())&&(r.locale=w),(S=null===(L=null===(j=u.getCurrentRouting())||void 0===j?void 0:j.countryCodes)||void 0===L?void 0:L[0])&&(r.countryCode=S),(P=u.getPriceListId())&&(r.priceListId=P),(y=u.getSalesChannelId())&&(r.salesChannelId=y),T=c.getInstance().customerStore.customer,(C=T?g(T):null)&&(r.customer=C),D=c.getInstance().cartStore.cart,(k=D?h(D):null)&&(r.cart=k),r.services=function(){var n=this,r=c.getInstance();return{searchProducts:function(r){return t(n,void 0,void 0,(function(){var t,n,o;return e(this,(function(e){switch(e.label){case 0:return[4,d.searchProducts(v(r))];case 1:return(null==(t=e.sent())?void 0:t.isSuccess)&&(null===(o=null===(n=t.data)||void 0===n?void 0:n.data)||void 0===o?void 0:o.length)?[2,t.data.data]:[2,[]]}}))}))},addItemToCart:function(o){var i=o.product,a=o.variant,u=o.quantity;return t(n,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,r.cartStore.addItem(a,i,null!=u?u:1)];case 1:return[2,{success:!!(null==(t=e.sent())?void 0:t.success)}]}}))}))},saveCustomerFormData:function(o){return t(n,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,r.customerStore.saveCustomerFormData({email:o.email,firstName:o.firstName,lastName:o.lastName,birthDate:o.birthDate||null,phone:o.phone||"",storefrontPopupId:o.popupId,subscriptions:o.subscriptions})];case 1:return t.sent(),[2]}}))}))},getLastViewedProducts:function(){return t(n,void 0,void 0,(function(){var t;return e(this,(function(e){return"function"==typeof(t=r.customerStore).getLastViewedProducts?[2,t.getLastViewedProducts()]:[2,[]]}))}))},formatVariantSellPrice:function(t){return t.formattedSellPrice||""},formatVariantDiscountPrice:function(t){return t.formattedDiscountPrice||null},hasVariantDiscount:function(t){return!!t.hasDiscount},getVariantDiscountPercentage:function(t){var e=t.discountPercentage;return null==e?null:"number"==typeof e?e.toString():e},redirectToProduct:function(t){return!!t.url&&(window.location.href=t.url,!0)},viewPopup:function(t){s.viewStorefrontPopup(t)}}}(),[2,r]}var D,T}))}))};function v(t){var e,n,r,o,i,s=null===(e=t.order)||void 0===e?void 0:e.map((function(t){return{direction:"ASC"===t.direction?a.ASC:a.DESC,type:t.type}}));return{input:{page:null!==(n=t.page)&&void 0!==n?n:1,perPage:null!==(r=t.perPage)&&void 0!==r?r:10,order:s,productIdList:t.productIdList,categoryIdList:t.categoryIdList,priceListId:null!==(o=t.priceListId)&&void 0!==o?o:u.getPriceListId(),salesChannelId:null!==(i=t.salesChannelId)&&void 0!==i?i:u.getSalesChannelId()}}}function g(t){return{email:t.email,firstName:t.firstName,lastName:t.lastName,birthDate:t.birthDate,phone:t.phone,gender:t.gender?String(t.gender):null,customerGroupIds:t.customerGroupIds||[],customerSegmentIds:t.customerSegmentIds||[],subscriptionStatus:t.subscriptionStatus?String(t.subscriptionStatus):null}}function h(t){var e,n,r=[],o=new Set,i=new Set,a=new Set,u=new Set,s=new Set,c=new Set;return t.items.forEach((function(t){var e,n,s,d=t.variant,l=(null==d?void 0:d.productId)||null,p=(null==d?void 0:d.id)||null,f=(null===(e=null==d?void 0:d.brand)||void 0===e?void 0:e.id)||null,m=(null===(n=null==d?void 0:d.categories)||void 0===n?void 0:n.map((function(t){return t.id})).filter(Boolean))||[];r.push({productId:l,variantId:p,brandId:f,categoryIds:m,quantity:t.quantity,finalPrice:t.finalPrice}),l&&o.add(l),p&&i.add(p),f&&a.add(f),m.forEach((function(t){return t&&u.add(t)})),(null===(s=t.discount)||void 0===s?void 0:s.campaignOfferId)&&c.add(t.discount.campaignOfferId)})),null===(e=t.campaignOffers)||void 0===e||e.forEach((function(t){t.campaignOfferId&&c.add(t.campaignOfferId)})),null===(n=t.orderAdjustments)||void 0===n||n.forEach((function(t){t.campaignId&&s.add(t.campaignId)})),{totalPrice:t.totalPrice,totalFinalPrice:t.totalFinalPrice,itemCount:t.itemCount,itemQuantity:t.itemQuantity,currencyCode:t.currencyCode||null,lines:r,productIds:Array.from(o),variantIds:Array.from(i),brandIds:Array.from(a),categoryIds:Array.from(u),appliedCampaignIds:Array.from(s),appliedCampaignOfferIds:Array.from(c),couponCode:t.couponCode||null}}function I(t){"undefined"!=typeof window&&(window.ikasPopupConfig&&(void 0!==t.customer&&(window.ikasPopupConfig.customer=t.customer),void 0!==t.cart&&(window.ikasPopupConfig.cart=t.cart),void 0!==t.customerToken&&(window.ikasPopupConfig.customerToken=t.customerToken||void 0)),"function"!=typeof window.updateIkasPopupContext?window.dispatchEvent(new CustomEvent(l,{detail:t})):window.updateIkasPopupContext(t))}function w(a){var s=this;a.router;var d=a.pageSpecificDataId,l=a.pageType;r.useEffect((function(){if("undefined"!=typeof window&&"undefined"!=typeof document){var r,a=!1,d=[],l=function(t,e){if(function(t){t.setAttribute("data-ikas-popup-widget","true"),!t.dataset.ikasPopupWidgetUrl&&t.src&&(t.dataset.ikasPopupWidgetUrl=t.src)}(t),"true"===t.dataset.ikasPopupWidgetLoaded)return e(),function(){};var n=function(){t.dataset.ikasPopupWidgetLoaded="true",e()},r=function(e){console.error("[@ikas/storefront] Failed to load popup widget script",t.src,e)};return t.addEventListener("load",n,{once:!0}),t.addEventListener("error",r,{once:!0}),function(){t.removeEventListener("load",n),t.removeEventListener("error",r)}},p=function(t){var e=window.location.href.includes("http://localhost:3333/")?"http://localhost:9000/popup-script-injector.iife.js":"/sf/assets/popup/popup-script-injector.iife.js";if(e){var n=function(){a||function(t){if("function"==typeof window.startIkasPopupWidget)try{window.startIkasPopupWidget(t)}catch(t){console.error("[@ikas/storefront] Failed to start popup widget",t)}}(t)},o=document.querySelector('script[data-ikas-popup-widget="true"]');if(o)r=l(o,n);else{var i=document.createElement("script");i.src=e,i.defer=!0,r=l(i,n),document.body.appendChild(i)}}},f=function(t){var e=window.location.href.includes("http://localhost:3333/")?"http://localhost:9000/style.css":"/sf/assets/popup/style.css";if(e&&!document.querySelector('link[href="'.concat(e,'"]'))){var n=document.createElement("link");n.rel="stylesheet",n.href=e,n.setAttribute("data-ikas-popup-widget","true");n.addEventListener("error",(function(t){console.error("[@ikas/storefront] Failed to load popup widget CSS",e,t)}),{once:!0}),document.head.appendChild(n)}};return t(s,void 0,void 0,(function(){var r,l,v;return e(this,(function(w){switch(w.label){case 0:return r=u.getStorefrontPopups()||[],[4,(C=r,t(s,void 0,void 0,(function(){var t,r,o,a,u;return e(this,(function(e){switch(e.label){case 0:if(!(t=C.map((function(t){return t.id})).filter(Boolean)).length)return[2,C];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,i({idList:t})];case 2:return(null==(r=e.sent())?void 0:r.isSuccess)&&(null===(u=r.data)||void 0===u?void 0:u.length)?(o=r.data,[2,C.map((function(t){var e=o.find((function(e){return e.id===t.id}));return e?n(n({},e),{isFilteredOnServerSide:t.isFilteredOnServerSide}):t}))]):[3,4];case 3:return a=e.sent(),console.error("[@ikas/storefront] Failed to fetch popup details",a),[3,4];case 4:return[2,C]}}))})))];case 1:return l=w.sent(),a?[2]:[4,m(l)];case 2:return v=w.sent(),window.ikasPopupConfig=v,p(v),f(),S=c.getInstance(),P=o((function(){var t=S.customerStore.customer;return t?{email:t.email,gender:t.gender,groupIds:(t.customerGroupIds||[]).join(","),segmentIds:(t.customerSegmentIds||[]).join(","),subscriptionStatus:t.subscriptionStatus}:null}),(function(){var t=S.customerStore.customer;I({customer:t?g(t):null,customerToken:u.getCustomerToken()||null})})),y=o((function(){var t=S.cartStore.cart;return t?{total:t.totalFinalPrice,itemCount:t.itemCount,quantity:t.itemQuantity,productSignature:t.items.map((function(t){var e,n;return"".concat((null===(e=t.variant)||void 0===e?void 0:e.productId)||"",":").concat((null===(n=t.variant)||void 0===n?void 0:n.id)||"",":").concat(t.quantity)})).join("|"),campaignSignature:(t.orderAdjustments||[]).map((function(t){return t.campaignId||""})).join("|"),couponCode:t.couponCode}:null}),(function(){var t=S.cartStore.cart;I({cart:t?h(t):null})})),d.push(P,y),[2]}var S,P,y,C}))})),function(){a=!0,null==r||r(),d.forEach((function(t){return t()})),d=[],"function"==typeof window.destroyIkasPopupWidget&&window.destroyIkasPopupWidget()}}}),[d,l])}export{w as usePopupWidget};
@@ -1 +1 @@
1
- import{__spreadArray as t,__assign as e,__awaiter as i,__generator as n}from'./../../../ext/tslib/tslib.es6.js';import r from"lodash/sortBy";import a from"lodash/cloneDeep";import{IkasCategory as o}from"../category/index.js";import{IkasProductVariant as s}from"./variant/index.js";import{IkasProductAttributeValue as u}from"./attribute-value/index.js";import{IkasProductVariantType as c}from"./variant-type/index.js";import{IkasBrand as l}from"../brand/index.js";import{IkasHTMLMetaData as d}from"../html-meta-data/index.js";import{IkasProductTag as p}from"./tag/index.js";import{IkasProductOptionPriceTypeEnum as f,IkasProductType as v}from"@ikas/storefront-models";export{IkasProductType}from"@ikas/storefront-models";import{IkasProductOptionSet as h}from"./option-set/index.js";import{makeObservable as m,observable as g,computed as b}from"mobx";import{IkasProductFunctions as V}from"@ikas/storefront-model-functions";import{IkasProductCampaign as y}from"./campaign/index.js";import{IkasStorefrontConfig as P}from"@ikas/storefront-config";import{IkasBaseStore as I}from"../../../store/base.js";import w from"lodash/groupBy";import{IkasProductBaseUnit as O}from"./base-unit/index.js";import{formatCurrency as S}from"../../../utils/currency.js";import"lodash/get";import T from"../../../store/product/index.js";import{IkasCustomerReviewList as j}from"../../ui/customer-review-list/index.js";import{IkasProductStar as C}from"./star/index.js";import{IkasProductCampaignOffer as L,IkasProductOffer as x}from"./campaign-offer/index.js";import{IkasProductGroup as R}from"./group/index.js";import{IkasImage as E}from"../image/index.js";import{IkasProductSalesChannel as G}from"./sales-channel/index.js";import{IkasProductTranslation as k}from"./translations/index.js";var A=function(){function A(V){void 0===V&&(V={});var w,E,D,U=this;this.metaData=null,this.brand=null,this.tags=null,this.productOptionSetId=null,this.translations=null,this.productOptionSet=null,this.campaigns=null,this.selectedVariantValues=[],this.isFiltered=!1,this.isStatic=!1,this.bundleProductCache={},this.productGroupItems=[],this.showVariantsInGroup=!1,this.selectVariantValue=function(i,n){var r,a=U.metaData,o=U.selectedVariantValues.map((function(t){return t.variantTypeId===i.variantTypeId?i:t})),s=U.variants.find((function(t){return t.isActive&&o.every((function(e){return t.variantValues.some((function(t){return t.id===e.id}))}))}));if(s)U.selectedVariantValues=o;else{var u=U.variantTypes.findIndex((function(t){return t.variantType.id===i.variantTypeId}));if(u>0){var c=U.variantTypes.slice(0,u),l=U.selectedVariantValues.filter((function(t){return c.some((function(e){return e.variantType.id===t.variantTypeId}))})),d=t(t([],l,!0),[i],!1);s=U.variants.find((function(t){return t.isActive&&d.every((function(e){return t.variantValues.some((function(t){return t.id===e.id}))}))}))}else{var p=o.slice(0,o.length-1);(s=U.variants.find((function(t){return t.isActive&&p.every((function(e){return t.variantValues.some((function(t){return t.id===e.id}))}))})))||(s=U.variants.find((function(t){return t.isActive&&t.variantValues.some((function(t){return t.id===i.id}))})))}if(!s)return;U.selectedVariantValues=s.variantValues}var f={};new URLSearchParams(window.location.search).forEach((function(t,i){var n;"vid"!==i&&(f=e(e({},f),((n={})[i]=t,n)))})),U.variantTypes.map((function(t){delete f[decodeURIComponent(t.variantType.slug)]}));var v=t(t([],Object.entries(f).map((function(t){var e=t[0],i=t[1];return"".concat(e,"=").concat(i)})),!0),U.variantTypes.map((function(t){var e=t.variantType,i=e.values.find((function(t){return U.selectedVariantValues.some((function(e){return e.id===t.id}))}));if(i)return"".concat(e.slug,"=").concat(i.slug)})),!0).filter((function(t){return!!t})).join("&");if(U.setOptionRealPrices(),!n){var h="/".concat(a.slug);if(v&&(h="/".concat(a.slug,"?").concat(v)),h===window.location.pathname)return;null===(r=I.getInstance().router)||void 0===r||r.replace(h,void 0,{shallow:!1,scroll:!1})}},this.getVariantUnitPriceText=function(t){var e,i,n=t.price;if(n.unitPrice&&U.baseUnit){var r=U.baseUnit.baseAmount,a=(null===(i=null===(e=U.baseUnit)||void 0===e?void 0:e.unit)||void 0===i?void 0:i.name)||"";return"".concat(S(n.unitPrice,n.currency||"",n.currencySymbol||"")," / ").concat(r&&1!==r?r:"").concat(a)}},this.getCampaigns=function(){return i(U,void 0,void 0,(function(){var t,e,i,r,a,o=this;return n(this,(function(n){switch(n.label){case 0:return t=I.getInstance(),e=t.customerStore.customer,i=e?e.customerGroupIds:null,r=this.variants.map((function(t){return t.id})),[4,T.getProductCampaigns({input:{customerGroupIds:i,salesChannelId:P.getSalesChannelId()||"",variantIds:r}})];case 1:return a=n.sent(),this.campaigns=a.data,this.campaigns?(this.campaigns.map((function(t){o.variants.map((function(e){var i;t.variantIds.some((function(t){return t===e.id}))&&(null===(i=e.campaigns)||void 0===i||i.push(t))}))})),[2,this.campaigns]):[2]}}))}))},this.getAvailableStockLocations=function(){return i(U,void 0,void 0,(function(){var t,e;return n(this,(function(i){switch(i.label){case 0:return t=this.variants.map((function(t){return t.id})),e=P.getPickupStockLocationIds(),[4,T.getVariantStockLocations({stockLocationIdList:e,variantIds:t})];case 1:return[2,i.sent().data||[]]}}))}))},this.updatePrices=function(){return i(U,void 0,void 0,(function(){var t,e,i,r,a=this;return n(this,(function(n){switch(n.label){case 0:return[4,T.searchProducts({input:{productIdList:[this.id],perPage:1,priceListId:P.getPriceListId(),salesChannelId:P.getSalesChannelId()}})];case 1:return t=n.sent(),(e=null===(r=null===(i=t.data)||void 0===i?void 0:i.data)||void 0===r?void 0:r.find((function(t){return t.id===a.id})))?(this.variants.forEach((function(t){var i=e.variants.find((function(e){return e.id===t.id}));i&&(t.prices=i.prices,t.baseBundlePrices=i.baseBundlePrices)})),[2]):[2]}}))}))},this.getCustomerReviews=function(t){return i(U,void 0,void 0,(function(){var i,r,a,o,s;return n(this,(function(n){switch(n.label){case 0:return i=!!(null===(o=this.selectedVariant.bundleSettings)||void 0===o?void 0:o.products.length),r=[this.id],i&&(null===(s=this.selectedVariant.bundleSettings)||void 0===s||s.products.forEach((function(t){r.push(t.productId)}))),[4,(a=new j(e(e(e({},i?{}:{productId:this.id}),{locale:null==t?void 0:t.locale,limit:null==t?void 0:t.limit,page:null==t?void 0:t.page,hasImage:null==t?void 0:t.hasImage,sortWithImagesFirst:null==t?void 0:t.sortWithImagesFirst}),i?{productIds:r}:{}))).getInitial()];case 1:return n.sent(),[2,a]}}))}))},this.getProductOptionSet=function(){return i(U,void 0,void 0,(function(){var t,e;return n(this,(function(i){switch(i.label){case 0:return this.productOptionSet?[2,!0]:this.productOptionSetId?[4,T.listProductOptionSet({id:{eq:this.productOptionSetId}})]:[2,!1];case 1:return(t=i.sent()).isSuccess&&(null===(e=t.data)||void 0===e?void 0:e.length)?(this.productOptionSet=t.data[0],this.setOptionPrices(),this.setOptionRealPrices(),[2,!0]):[2,!1]}}))}))},this.initBundleProducts=function(){return i(U,void 0,void 0,(function(){var t,e,i,r,a,o;return n(this,(function(n){switch(n.label){case 0:return t="","undefined"!=typeof window&&(e=new URLSearchParams(window.location.search),t=e.get("editLineID")||""),t?(i=null===(a=I.getInstance().cartStore.cart)||void 0===a?void 0:a.items.find((function(e){return e.id===t})))&&(r=this.variants.find((function(t){return t.id===i.variant.id})))?(this.selectedVariantValues=r.variantValues,[4,this.getBundleProductsOfVariant(r)]):[3,2]:[3,3];case 1:n.sent(),null===(o=r.bundleSettings)||void 0===o||o.products.forEach((function(t){var e,n,r;try{var a=null===(e=i.variant.bundleProducts)||void 0===e?void 0:e.find((function(e){return e.id===t.id})),o=t.product.variants.find((function(t){return t.id===(null==a?void 0:a.variant.id)}));t.product.selectedVariantValues=o.variantValues,t.quantity=(null===(r=null===(n=i.variant.bundleProducts)||void 0===n?void 0:n.find((function(t){return t.variant.id===o.id})))||void 0===r?void 0:r.quantity)||0}catch(t){console.error(t)}})),n.label=2;case 2:return[3,5];case 3:return[4,this.getBundleProductsOfVariant(this.selectedVariant)];case 4:n.sent(),n.label=5;case 5:return[2]}}))}))},this.setShowVariantsInGroup=function(t){U.showVariantsInGroup=t},this.getBundleProductsOfVariant=function(t){return i(U,void 0,void 0,(function(){var e,i,r,o,s,u,c=this;return n(this,(function(n){switch(n.label){case 0:return(null==(e=null===(r=t.bundleSettings)||void 0===r?void 0:r.products.map((function(t){return t.productId})).filter((function(t){return-1===Object.keys(c.bundleProductCache).indexOf(t)})))?void 0:e.length)?[4,T.searchProducts({input:{productIdList:e,perPage:200,priceListId:P.getPriceListId(),salesChannelId:P.getSalesChannelId()}})]:[3,2];case 1:(i=n.sent()).isSuccess&&(null===(s=null===(o=i.data)||void 0===o?void 0:o.data)||void 0===s||s.forEach((function(t){c.bundleProductCache[t.id]=t}))),n.label=2;case 2:return null===(u=t.bundleSettings)||void 0===u||u.products.forEach((function(t){var e=c.bundleProductCache[t.productId];t.setProduct(new A(a(e)))})),[2]}}))}))},this.getSubscriptionPlanOfVariant=function(t){return i(U,void 0,void 0,(function(){var e,i=this;return n(this,(function(n){return null===(e=t.subscriptionPlan)||void 0===e||e.periods.forEach((function(t,e){t.setProduct(i),0===e&&(t.isSelected=!0)})),[2]}))}))},this.setOptionRealPrices=function(){var t,e=U.selectedVariant||U.variants[0];if(e){var i=e.price.priceListId;null===(t=U.productOptionSet)||void 0===t||t.options.forEach((function(t){var e;if(t.selectSettings)t.selectSettings.values.forEach((function(t){var e;if(t.priceType===f.RATIO&&t.initPrice)if(t.otherPrices){var n=(null===(e=t.otherPrices.find((function(t){return t.priceListId===i})))||void 0===e?void 0:e.price)||t.initPrice||1;t.price=U.selectedVariant.price.finalPrice*n/100}else t.price=U.selectedVariant.price.finalPrice*t.initPrice/100}));else if(t.priceType===f.RATIO&&t.initPrice)if(t.otherPrices){var n=(null===(e=t.otherPrices.find((function(t){return t.priceListId===i})))||void 0===e?void 0:e.price)||t.initPrice||1;t.price=U.selectedVariant.price.finalPrice*n/100}else t.price=U.selectedVariant.price.finalPrice*t.initPrice/100}))}},this.setOptionPrices=function(){var t,e=U.variants[0];if(e){var i=e.price.priceListId;null===(t=U.productOptionSet)||void 0===t||t.options.forEach((function(t){var n,r;if(t.selectSettings&&t.selectSettings.values.forEach((function(t){var n,r;if(t.otherPrices)if(t.priceType===f.RATIO){var a=(null===(n=t.otherPrices.find((function(t){return t.priceListId===i})))||void 0===n?void 0:n.price)||t.price||1;t.price=e.price.finalPrice*a/100}else t.price=(null===(r=t.otherPrices.find((function(t){return t.priceListId===i})))||void 0===r?void 0:r.price)||t.price})),t.otherPrices)if(t.priceType===f.RATIO){var a=(null===(n=t.otherPrices.find((function(t){return t.priceListId===i})))||void 0===n?void 0:n.price)||t.price||1;t.price=e.price.finalPrice*a/100}else t.price=(null===(r=t.otherPrices.find((function(t){return t.priceListId===i})))||void 0===r?void 0:r.price)||t.price}))}},this.id=V.id||Date.now()+"",this.name=V.name||"",this.type=V.type||v.PHYSICAL,this.description=V.description||"",this.shortDescription=V.shortDescription||"",this.metaData=V.metaData?new d(V.metaData):null,this.brand=V.brand?new l(V.brand):null,this.categories=V.categories?V.categories.map((function(t){return new o(t)})):[],this.deleted=V.deleted||null,this.tags=V.tags?V.tags.map((function(t){return new p(t)})):[],this.variants=V.variants?V.variants.map((function(t){return new s(t)})):[],this.attributes=V.attributes?V.attributes.map((function(t){return new u(t)})):[],this.variantTypes=V.variantTypes?V.variantTypes.map((function(t){return new c(t)})):[],this.productOptionSetId=V.productOptionSetId||null,this.averageRating=null!==(w=V.averageRating)&&void 0!==w?w:null,this.reviewCount=null!==(E=V.reviewCount)&&void 0!==E?E:null,this.stars=V.stars?V.stars.map((function(t){return new C(t)})):null,this.baseUnit=V.baseUnit?new O(V.baseUnit):null,this.campaigns=(null===(D=V.campaigns)||void 0===D?void 0:D.map((function(t){return new y(t)})))||null,this.selectedVariantValues=V.selectedVariantValues||[],this.productOptionSet=V.productOptionSet?new h(V.productOptionSet):null,this.variantTypes=r(this.variantTypes,"order"),this.groupVariantsByVariantTypeId=V.groupVariantsByVariantTypeId||null,this.dynamicPriceListIds=V.dynamicPriceListIds||null,this.productVolumeDiscountId=V.productVolumeDiscountId||null,this.campaignOffers=V.campaignOffers?V.campaignOffers.map((function(t){return new L(t)})):null,this.appliedCampaignOffer=V.appliedCampaignOffer,this.offers=V.offers?V.offers.map((function(t){return new x(t)})):void 0,this.productGroup=V.productGroup?new R(V.productGroup):null,this.salesChannels=V.salesChannels?V.salesChannels.map((function(t){return new G(t)})):null,this.translations=V.translations?V.translations.map((function(t){return new k(t)})):null,this.productGroupItems=V.productGroupItems,this.variants.forEach((function(t){return t.product=U})),this.setOptionPrices(),this.setOptionRealPrices(),this.customerReviews=V.customerReviews?new j(V.customerReviews):null,m(this,{selectedVariantValues:g,isFiltered:g,isStatic:g,showVariantsInGroup:g,hasVariant:b,hasStock:b,hasValidProductOptionValues:b,href:b,productHref:b,mainVariantType:b,mainVariantValue:b,selectedVariant:b,displayedVariantTypes:b,isCustomerReviewEnabled:b,isCustomerReviewLoginRequired:b,isAddToCartEnabled:b,groupedAttributeValues:b,selectedVariantUnitPriceText:b,displayedProductGroups:b})}return Object.defineProperty(A.prototype,"hasVariant",{get:function(){return V.hasVariant(this,this.showVariantsInGroup)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"hasStock",{get:function(){return this.isStatic?this.selectedVariant.hasStock:V.hasStock(this)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"hasValidProductOptionValues",{get:function(){return!this.productOptionSet||this.productOptionSet.hasValidValues},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"href",{get:function(){return V.getSelectedVariantHref(this,this.selectedVariantValues)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"productHref",{get:function(){return this.groupVariantsByVariantTypeId||this.isFiltered?this.href:V.getProductHref(this)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"mainVariantType",{get:function(){return V.getMainVariantType(this)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"mainVariantValue",{get:function(){return V.getMainVariantValue(this.selectedVariantValues)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"selectedVariant",{get:function(){if(!this.hasVariant)return this.variants[0];var t=this.selectedVariantValues.map((function(t){return t.id}));return this.variants.find((function(e){return e.variantValues.every((function(e){return t.includes(e.id)}))}))},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"displayedVariantTypes",{get:function(){return this.hasVariant?V.getDisplayedVariantTypes(this,this.selectedVariantValues):[]},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"isCustomerReviewEnabled",{get:function(){return P.isCustomerReviewEnabled()},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"isCustomerReviewLoginRequired",{get:function(){return P.isCustomerReviewLoginRequired()},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"isAddToCartEnabled",{get:function(){var t,e=!0;return null===(t=this.selectedVariant.bundleSettings)||void 0===t||t.products.forEach((function(t){0===t.quantity&&null!==t.minQuantity&&0!==t.minQuantity&&(e=!1)})),e&&this.hasValidProductOptionValues&&(this.selectedVariant.hasStock||this.selectedVariant.sellIfOutOfStock)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"groupedAttributeValues",{get:function(){var t,e=w(this.attributes,"productAttributeId");return(null===(t=this.attributes)||void 0===t?void 0:t.map((function(t){var i=t.productAttributeId;if(i){var n=e[i];return(null==n?void 0:n.length)&&n[0].productAttribute?{attribute:n[0].productAttribute,values:n}:void 0}})).filter((function(t){return!!t})))||[]},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"selectedVariantUnitPriceText",{get:function(){return this.getVariantUnitPriceText(this.selectedVariant)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"displayedProductGroups",{get:function(){var e,i=this,n=[],a=[];return null===(e=this.productGroupItems)||void 0===e||e.forEach((function(t){t.groupValues.forEach((function(t){n.includes(t.name)||n.push(t.name)}))})),n.forEach((function(e){var n,o={name:e,items:[]};i.productGroupItems=r(i.productGroupItems,(function(t){var e;return parseInt((null===(e=t.order)||void 0===e?void 0:e.value)||"999",10)})),null===(n=i.productGroupItems)||void 0===n||n.forEach((function(n){var r,a,s,u=n.groupValues.find((function(t){return t.name===e}));if(u&&!o.items.some((function(t){return t.value===u.value}))){var c="";if(n.productId===i.id)c=i.href;else{var l=(null===(r=i.productGroup)||void 0===r?void 0:r.values.filter((function(t){return t.name!==e})))||[],d=t(t([],l,!0),[u],!1),p=null===(a=i.productGroupItems)||void 0===a?void 0:a.find((function(t){return d.every((function(e){return t.groupValues.some((function(t){return e.name===t.name&&e.value===t.value}))}))}));c=p?p.href:n.href}o.items.push({image:n.image?new E(n.image):null,href:c,value:u.value,isSelected:(null===(s=i.productGroupItems)||void 0===s?void 0:s.some((function(t){return t.groupValues.some((function(t){return t.value===u.value}))&&t.productId===i.id})))||!1,isSelectable:function(){var n,r,a=(null===(n=i.productGroup)||void 0===n?void 0:n.values.filter((function(t){return t.name!==e})))||[],o=t(t([],a,!0),[u],!1);return!!(null===(r=i.productGroupItems)||void 0===r?void 0:r.find((function(t){return o.every((function(e){return t.groupValues.some((function(t){return e.name===t.name&&e.value===t.value}))}))})))}(),hasStock:n.hasStock})}})),a.push(o)})),a},enumerable:!1,configurable:!0}),A.prototype.dispose=function(){var t,e,i=this;(null===(t=this.variants)||void 0===t||t.forEach((function(t){var e,i;t.product=null,t.bundleSettings&&(null===(e=t.bundleSettings.products)||void 0===e||e.forEach((function(t){t.product=null}))),t.subscriptionPlan&&(null===(i=t.subscriptionPlan.periods)||void 0===i||i.forEach((function(t){t.product=null})))})),this.bundleProductCache={},null===(e=this.offers)||void 0===e||e.forEach((function(t){t.product=null})),"undefined"!=typeof window)&&(window.requestIdleCallback||function(t){return window.setTimeout(t,200)})((function(){try{i.variants=[],i.attributes=[],i.variantTypes=[],i.categories=[],i.tags=null,i.campaigns=null,i.campaignOffers=null,i.productOptionSet=null,i.productGroup=null,i.salesChannels=null,i.translations=null,i.customerReviews=null,i.offers=void 0,i.metaData=null,i.brand=null,i.selectedVariantValues=[]}catch(t){}}))},A}();export{A as IkasProduct};
1
+ import{__spreadArray as t,__assign as e,__awaiter as i,__generator as n}from'./../../../ext/tslib/tslib.es6.js';import r from"lodash/sortBy";import a from"lodash/cloneDeep";import{IkasCategory as o}from"../category/index.js";import{IkasProductVariant as s}from"./variant/index.js";import{IkasProductAttributeValue as u}from"./attribute-value/index.js";import{IkasProductVariantType as c}from"./variant-type/index.js";import{IkasBrand as d}from"../brand/index.js";import{IkasHTMLMetaData as l}from"../html-meta-data/index.js";import{IkasProductTag as p}from"./tag/index.js";import{IkasProductOptionPriceTypeEnum as f,IkasProductType as v}from"@ikas/storefront-models";export{IkasProductType}from"@ikas/storefront-models";import{IkasProductOptionSet as h}from"./option-set/index.js";import{makeObservable as m,observable as g,computed as b}from"mobx";import{IkasProductFunctions as V}from"@ikas/storefront-model-functions";import{IkasProductCampaign as y}from"./campaign/index.js";import{IkasStorefrontConfig as P}from"@ikas/storefront-config";import{IkasBaseStore as I}from"../../../store/base.js";import O from"lodash/groupBy";import{IkasProductBaseUnit as S}from"./base-unit/index.js";import{formatCurrency as w}from"../../../utils/currency.js";import"lodash/get";import T from"../../../store/product/index.js";import{IkasCustomerReviewList as j}from"../../ui/customer-review-list/index.js";import{IkasProductStar as C}from"./star/index.js";import{IkasProductCampaignOffer as L,IkasProductOffer as x}from"./campaign-offer/index.js";import{IkasProductGroup as R}from"./group/index.js";import{IkasImage as G}from"../image/index.js";import{IkasProductSalesChannel as E}from"./sales-channel/index.js";import{IkasProductTranslation as k}from"./translations/index.js";var A=function(){function A(V){void 0===V&&(V={});var O,G,D,U=this;this.metaData=null,this.brand=null,this.tags=null,this.productOptionSetId=null,this.translations=null,this.productOptionSet=null,this.campaigns=null,this.selectedVariantValues=[],this.isFiltered=!1,this.isStatic=!1,this.bundleProductCache={},this.productGroupItems=[],this.showVariantsInGroup=!1,this.selectVariantValue=function(i,n){var r,a=U.metaData,o=U.selectedVariantValues.map((function(t){return t.variantTypeId===i.variantTypeId?i:t})),s=U.variants.find((function(t){return t.isActive&&o.every((function(e){return t.variantValues.some((function(t){return t.id===e.id}))}))}));if(s)U.selectedVariantValues=o;else{var u=U.variantTypes.findIndex((function(t){return t.variantType.id===i.variantTypeId}));if(u>0){var c=U.variantTypes.slice(0,u),d=U.selectedVariantValues.filter((function(t){return c.some((function(e){return e.variantType.id===t.variantTypeId}))})),l=t(t([],d,!0),[i],!1);s=U.variants.find((function(t){return t.isActive&&l.every((function(e){return t.variantValues.some((function(t){return t.id===e.id}))}))}))}else{var p=o.slice(0,o.length-1);(s=U.variants.find((function(t){return t.isActive&&p.every((function(e){return t.variantValues.some((function(t){return t.id===e.id}))}))})))||(s=U.variants.find((function(t){return t.isActive&&t.variantValues.some((function(t){return t.id===i.id}))})))}if(!s)return;U.selectedVariantValues=s.variantValues}var f={};new URLSearchParams(window.location.search).forEach((function(t,i){var n;"vid"!==i&&(f=e(e({},f),((n={})[i]=t,n)))})),U.variantTypes.map((function(t){delete f[decodeURIComponent(t.variantType.slug)]}));var v=t(t([],Object.entries(f).map((function(t){var e=t[0],i=t[1];return"".concat(e,"=").concat(i)})),!0),U.variantTypes.map((function(t){var e=t.variantType,i=e.values.find((function(t){return U.selectedVariantValues.some((function(e){return e.id===t.id}))}));if(i)return"".concat(e.slug,"=").concat(i.slug)})),!0).filter((function(t){return!!t})).join("&");if(U.setOptionRealPrices(),!n){var h="/".concat(a.slug);if(v&&(h="/".concat(a.slug,"?").concat(v)),h===window.location.pathname)return;null===(r=I.getInstance().router)||void 0===r||r.replace(h,void 0,{shallow:!1,scroll:!1})}},this.getVariantUnitPriceText=function(t){var e,i,n=t.price;if(n.unitPrice&&U.baseUnit){var r=U.baseUnit.baseAmount,a=(null===(i=null===(e=U.baseUnit)||void 0===e?void 0:e.unit)||void 0===i?void 0:i.name)||"";return"".concat(w(n.unitPrice,n.currency||"",n.currencySymbol||"")," / ").concat(r&&1!==r?r:"").concat(a)}},this.getCampaigns=function(){return i(U,void 0,void 0,(function(){var t,e,i,r,a,o=this;return n(this,(function(n){switch(n.label){case 0:return t=I.getInstance(),e=t.customerStore.customer,i=e?e.customerGroupIds:null,r=this.variants.map((function(t){return t.id})),[4,T.getProductCampaigns({input:{customerGroupIds:i,salesChannelId:P.getSalesChannelId()||"",variantIds:r}})];case 1:return a=n.sent(),this.campaigns=a.data,this.campaigns?(this.campaigns.map((function(t){o.variants.map((function(e){var i;t.variantIds.some((function(t){return t===e.id}))&&(null===(i=e.campaigns)||void 0===i||i.push(t))}))})),[2,this.campaigns]):[2]}}))}))},this.getAvailableStockLocations=function(){return i(U,void 0,void 0,(function(){var t,e;return n(this,(function(i){switch(i.label){case 0:return t=this.variants.map((function(t){return t.id})),e=P.getPickupStockLocationIds(),[4,T.getVariantStockLocations({stockLocationIdList:e,variantIds:t})];case 1:return[2,i.sent().data||[]]}}))}))},this.updatePrices=function(){return i(U,void 0,void 0,(function(){var t,e,i,r,a=this;return n(this,(function(n){switch(n.label){case 0:return[4,T.searchProducts({input:{productIdList:[this.id],perPage:1,priceListId:P.getPriceListId(),salesChannelId:P.getSalesChannelId()}})];case 1:return t=n.sent(),(e=null===(r=null===(i=t.data)||void 0===i?void 0:i.data)||void 0===r?void 0:r.find((function(t){return t.id===a.id})))?(this.variants.forEach((function(t){var i=e.variants.find((function(e){return e.id===t.id}));i&&(t.prices=i.prices,t.baseBundlePrices=i.baseBundlePrices)})),[2]):[2]}}))}))},this.getCustomerReviews=function(t){return i(U,void 0,void 0,(function(){var i,r,a,o,s;return n(this,(function(n){switch(n.label){case 0:return i=!!(null===(o=this.selectedVariant.bundleSettings)||void 0===o?void 0:o.products.length),r=[this.id],i&&(null===(s=this.selectedVariant.bundleSettings)||void 0===s||s.products.forEach((function(t){r.push(t.productId)}))),[4,(a=new j(e(e(e({},i?{}:{productId:this.id}),{locale:null==t?void 0:t.locale,limit:null==t?void 0:t.limit,page:null==t?void 0:t.page,hasImage:null==t?void 0:t.hasImage,sortWithImagesFirst:null==t?void 0:t.sortWithImagesFirst}),i?{productIds:r}:{}))).getInitial()];case 1:return n.sent(),[2,a]}}))}))},this.getProductOptionSet=function(){return i(U,void 0,void 0,(function(){var t,e;return n(this,(function(i){switch(i.label){case 0:return this.productOptionSet?[2,!0]:this.productOptionSetId?[4,T.listProductOptionSet({id:{eq:this.productOptionSetId}})]:[2,!1];case 1:return(t=i.sent()).isSuccess&&(null===(e=t.data)||void 0===e?void 0:e.length)?(this.productOptionSet=t.data[0],this.setOptionPrices(),this.setOptionRealPrices(),[2,!0]):[2,!1]}}))}))},this.initBundleProducts=function(){return i(U,void 0,void 0,(function(){var t,e,i,r,a,o;return n(this,(function(n){switch(n.label){case 0:return t="","undefined"!=typeof window&&(e=new URLSearchParams(window.location.search),t=e.get("editLineID")||""),t?(i=null===(a=I.getInstance().cartStore.cart)||void 0===a?void 0:a.items.find((function(e){return e.id===t})))&&(r=this.variants.find((function(t){return t.id===i.variant.id})))?(this.selectedVariantValues=r.variantValues,[4,this.getBundleProductsOfVariant(r)]):[3,2]:[3,3];case 1:n.sent(),null===(o=r.bundleSettings)||void 0===o||o.products.forEach((function(t){var e,n,r;try{var a=null===(e=i.variant.bundleProducts)||void 0===e?void 0:e.find((function(e){return e.id===t.id})),o=t.product.variants.find((function(t){return t.id===(null==a?void 0:a.variant.id)}));t.product.selectedVariantValues=o.variantValues,t.quantity=(null===(r=null===(n=i.variant.bundleProducts)||void 0===n?void 0:n.find((function(t){return t.variant.id===o.id})))||void 0===r?void 0:r.quantity)||0}catch(t){console.error(t)}})),n.label=2;case 2:return[3,5];case 3:return[4,this.getBundleProductsOfVariant(this.selectedVariant)];case 4:n.sent(),n.label=5;case 5:return[2]}}))}))},this.setShowVariantsInGroup=function(t){U.showVariantsInGroup=t},this.getBundleProductsOfVariant=function(t){return i(U,void 0,void 0,(function(){var e,i,r,o,s,u,c=this;return n(this,(function(n){switch(n.label){case 0:return(null==(e=null===(r=t.bundleSettings)||void 0===r?void 0:r.products.map((function(t){return t.productId})).filter((function(t){return-1===Object.keys(c.bundleProductCache).indexOf(t)})))?void 0:e.length)?[4,T.searchProducts({input:{productIdList:e,perPage:200,priceListId:P.getPriceListId(),salesChannelId:P.getSalesChannelId()}})]:[3,2];case 1:(i=n.sent()).isSuccess&&(null===(s=null===(o=i.data)||void 0===o?void 0:o.data)||void 0===s||s.forEach((function(t){c.bundleProductCache[t.id]=t}))),n.label=2;case 2:return null===(u=t.bundleSettings)||void 0===u||u.products.forEach((function(t){var e=c.bundleProductCache[t.productId];t.setProduct(new A(a(e)))})),[2]}}))}))},this.getSubscriptionPlanOfVariant=function(t){return i(U,void 0,void 0,(function(){var e,i=this;return n(this,(function(n){return null===(e=t.subscriptionPlan)||void 0===e||e.periods.forEach((function(t,e){t.setProduct(i),0===e&&(t.isSelected=!0)})),[2]}))}))},this.setOptionRealPrices=function(){var t,e=U.selectedVariant||U.variants[0];if(e){var i=e.price.priceListId;null===(t=U.productOptionSet)||void 0===t||t.options.forEach((function(t){var e;if(t.selectSettings)t.selectSettings.values.forEach((function(t){var e;if(t.priceType===f.RATIO&&t.initPrice)if(t.otherPrices){var n=(null===(e=t.otherPrices.find((function(t){return t.priceListId===i})))||void 0===e?void 0:e.price)||t.initPrice||1;t.price=U.selectedVariant.price.finalPrice*n/100}else t.price=U.selectedVariant.price.finalPrice*t.initPrice/100}));else if(t.priceType===f.RATIO&&t.initPrice)if(t.otherPrices){var n=(null===(e=t.otherPrices.find((function(t){return t.priceListId===i})))||void 0===e?void 0:e.price)||t.initPrice||1;t.price=U.selectedVariant.price.finalPrice*n/100}else t.price=U.selectedVariant.price.finalPrice*t.initPrice/100}))}},this.setOptionPrices=function(){var t,e=U.variants[0];if(e){var i=e.price.priceListId;null===(t=U.productOptionSet)||void 0===t||t.options.forEach((function(t){var n,r;if(t.selectSettings&&t.selectSettings.values.forEach((function(t){var n,r;if(t.otherPrices)if(t.priceType===f.RATIO){var a=(null===(n=t.otherPrices.find((function(t){return t.priceListId===i})))||void 0===n?void 0:n.price)||t.price||1;t.price=e.price.finalPrice*a/100}else t.price=(null===(r=t.otherPrices.find((function(t){return t.priceListId===i})))||void 0===r?void 0:r.price)||t.price})),t.otherPrices)if(t.priceType===f.RATIO){var a=(null===(n=t.otherPrices.find((function(t){return t.priceListId===i})))||void 0===n?void 0:n.price)||t.price||1;t.price=e.price.finalPrice*a/100}else t.price=(null===(r=t.otherPrices.find((function(t){return t.priceListId===i})))||void 0===r?void 0:r.price)||t.price}))}},this.id=V.id||Date.now()+"",this.name=V.name||"",this.type=V.type||v.PHYSICAL,this.description=V.description||"",this.shortDescription=V.shortDescription||"",this.metaData=V.metaData?new l(V.metaData):null,this.brand=V.brand?new d(V.brand):null,this.categories=V.categories?V.categories.map((function(t){return new o(t)})):[],this.deleted=V.deleted||null,this.tags=V.tags?V.tags.map((function(t){return new p(t)})):[],this.variants=V.variants?V.variants.map((function(t){return new s(t)})):[],this.attributes=V.attributes?V.attributes.map((function(t){return new u(t)})):[],this.variantTypes=V.variantTypes?V.variantTypes.map((function(t){return new c(t)})):[],this.productOptionSetId=V.productOptionSetId||null,this.averageRating=null!==(O=V.averageRating)&&void 0!==O?O:null,this.reviewCount=null!==(G=V.reviewCount)&&void 0!==G?G:null,this.stars=V.stars?V.stars.map((function(t){return new C(t)})):null,this.baseUnit=V.baseUnit?new S(V.baseUnit):null,this.campaigns=(null===(D=V.campaigns)||void 0===D?void 0:D.map((function(t){return new y(t)})))||null,this.selectedVariantValues=V.selectedVariantValues||[],this.productOptionSet=V.productOptionSet?new h(V.productOptionSet):null,this.variantTypes=r(this.variantTypes,"order"),this.groupVariantsByVariantTypeId=V.groupVariantsByVariantTypeId||null,this.dynamicPriceListIds=V.dynamicPriceListIds||null,this.productVolumeDiscountId=V.productVolumeDiscountId||null,this.campaignOffers=V.campaignOffers?V.campaignOffers.map((function(t){return new L(t)})):null,this.appliedCampaignOffer=V.appliedCampaignOffer,this.offers=V.offers?V.offers.map((function(t){return new x(t)})):void 0,this.productGroup=V.productGroup?new R(V.productGroup):null,this.salesChannels=V.salesChannels?V.salesChannels.map((function(t){return new E(t)})):null,this.translations=V.translations?V.translations.map((function(t){return new k(t)})):null,this.productGroupItems=V.productGroupItems,this.variants.forEach((function(t){return t.product=U})),this.setOptionPrices(),this.setOptionRealPrices(),this.customerReviews=V.customerReviews?new j(V.customerReviews):null,m(this,{selectedVariantValues:g,isFiltered:g,isStatic:g,showVariantsInGroup:g,hasVariant:b,hasStock:b,hasValidProductOptionValues:b,href:b,productHref:b,mainVariantType:b,mainVariantValue:b,selectedVariant:b,displayedVariantTypes:b,isCustomerReviewEnabled:b,isCustomerReviewLoginRequired:b,isAddToCartEnabled:b,groupedAttributeValues:b,selectedVariantUnitPriceText:b,displayedProductGroups:b})}return Object.defineProperty(A.prototype,"hasVariant",{get:function(){return V.hasVariant(this,this.showVariantsInGroup)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"hasStock",{get:function(){return this.isStatic?this.selectedVariant.hasStock:V.hasStock(this)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"hasValidProductOptionValues",{get:function(){return!this.productOptionSet||this.productOptionSet.hasValidValues},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"href",{get:function(){return V.getSelectedVariantHref(this,this.selectedVariantValues)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"productHref",{get:function(){return this.groupVariantsByVariantTypeId||this.isFiltered?this.href:V.getProductHref(this)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"mainVariantType",{get:function(){return V.getMainVariantType(this)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"mainVariantValue",{get:function(){return V.getMainVariantValue(this.selectedVariantValues)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"selectedVariant",{get:function(){if(!this.hasVariant)return this.variants[0];var t=this.selectedVariantValues.map((function(t){return t.id}));return this.variants.find((function(e){return e.variantValues.every((function(e){return t.includes(e.id)}))}))},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"displayedVariantTypes",{get:function(){return this.hasVariant?V.getDisplayedVariantTypes(this,this.selectedVariantValues):[]},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"isCustomerReviewEnabled",{get:function(){return P.isCustomerReviewEnabled()},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"isCustomerReviewLoginRequired",{get:function(){return P.isCustomerReviewLoginRequired()},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"isAddToCartEnabled",{get:function(){var t,e=!0;return null===(t=this.selectedVariant.bundleSettings)||void 0===t||t.products.forEach((function(t){0===t.quantity&&null!==t.minQuantity&&0!==t.minQuantity&&(e=!1)})),e&&this.hasValidProductOptionValues&&(this.selectedVariant.hasStock||this.selectedVariant.sellIfOutOfStock)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"groupedAttributeValues",{get:function(){var t,e=O(this.attributes,"productAttributeId");return(null===(t=this.attributes)||void 0===t?void 0:t.map((function(t){var i=t.productAttributeId;if(i){var n=e[i];return(null==n?void 0:n.length)&&n[0].productAttribute?{attribute:n[0].productAttribute,values:n}:void 0}})).filter((function(t){return!!t})))||[]},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"selectedVariantUnitPriceText",{get:function(){return this.getVariantUnitPriceText(this.selectedVariant)},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"displayedProductGroups",{get:function(){var e,i=this,n=[],a=[];return null===(e=this.productGroupItems)||void 0===e||e.forEach((function(t){t.groupValues.forEach((function(t){n.includes(t.name)||n.push(t.name)}))})),n.forEach((function(e){var n,o={name:e,items:[]};i.productGroupItems=r(i.productGroupItems,(function(t){var e;return parseInt((null===(e=t.order)||void 0===e?void 0:e.value)||"999",10)})),null===(n=i.productGroupItems)||void 0===n||n.forEach((function(n){var r,a,s,u=n.groupValues.find((function(t){return t.name===e}));if(u&&!o.items.some((function(t){return t.value===u.value}))){var c="";if(n.productId===i.id)c=i.href;else{var d=(null===(r=i.productGroup)||void 0===r?void 0:r.values.filter((function(t){return t.name!==e})))||[],l=t(t([],d,!0),[u],!1),p=null===(a=i.productGroupItems)||void 0===a?void 0:a.find((function(t){return l.every((function(e){return t.groupValues.some((function(t){return e.name===t.name&&e.value===t.value}))}))}));c=p?p.href:n.href}o.items.push({image:n.image?new G(n.image):null,href:c,value:u.value,isSelected:(null===(s=i.productGroupItems)||void 0===s?void 0:s.some((function(t){return t.groupValues.some((function(t){return t.value===u.value}))&&t.productId===i.id})))||!1,isSelectable:function(){var n,r,a=(null===(n=i.productGroup)||void 0===n?void 0:n.values.filter((function(t){return t.name!==e})))||[],o=t(t([],a,!0),[u],!1);return!!(null===(r=i.productGroupItems)||void 0===r?void 0:r.find((function(t){return o.every((function(e){return t.groupValues.some((function(t){return e.name===t.name&&e.value===t.value}))}))})))}(),hasStock:n.hasStock})}})),a.push(o)})),a},enumerable:!1,configurable:!0}),A.prototype.dispose=function(){},A}();export{A as IkasProduct};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "5.0.71",
3
+ "version": "5.0.72",
4
4
  "description": "Storefront functionality for ikas storefront themes.",
5
5
  "author": "ikas",
6
6
  "license": "ISC",
@@ -23,11 +23,11 @@
23
23
  "swiper": "11.0.6"
24
24
  },
25
25
  "devDependencies": {
26
- "@ikas/storefront-api": "^5.0.71",
27
- "@ikas/storefront-config": "^5.0.71",
28
- "@ikas/storefront-model-functions": "^5.0.71",
29
- "@ikas/storefront-models": "^5.0.71",
30
- "@ikas/storefront-providers": "^5.0.71",
26
+ "@ikas/storefront-api": "^5.0.72",
27
+ "@ikas/storefront-config": "^5.0.72",
28
+ "@ikas/storefront-model-functions": "^5.0.72",
29
+ "@ikas/storefront-models": "^5.0.72",
30
+ "@ikas/storefront-providers": "^5.0.72",
31
31
  "@ikas/localized-address": "1.0.0-beta.6",
32
32
  "@adyen/adyen-web": "^5.57.0",
33
33
  "@rollup/plugin-commonjs": "^22.0.0",
@@ -62,11 +62,11 @@
62
62
  },
63
63
  "peerDependencies": {
64
64
  "@ikas/localized-address": "1.0.0-beta.6",
65
- "@ikas/storefront-api": "^5.0.71",
66
- "@ikas/storefront-config": "^5.0.71",
67
- "@ikas/storefront-model-functions": "^5.0.71",
68
- "@ikas/storefront-models": "^5.0.71",
69
- "@ikas/storefront-providers": "^5.0.71",
65
+ "@ikas/storefront-api": "^5.0.72",
66
+ "@ikas/storefront-config": "^5.0.72",
67
+ "@ikas/storefront-model-functions": "^5.0.72",
68
+ "@ikas/storefront-models": "^5.0.72",
69
+ "@ikas/storefront-providers": "^5.0.72",
70
70
  "mobx": "^6.1.3",
71
71
  "mobx-react-lite": "^3.1.5",
72
72
  "next": "12.2.0",