@ikas/bp-storefront 1.4.0-beta.89 → 1.4.0-beta.90
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{IkasStorefrontConfig as c}from"../../../packages/storefront-config/src/index.js";function n(c){return
|
|
1
|
+
import{IkasStorefrontConfig as c}from"../../../packages/storefront-config/src/index.js";function n(c){return o(c,1080)}function i(c){return o(c,180)}function o(n,i){var o;if(!(null==n?void 0:n.id))return"";var a=c.cdnUrl,t=c.videoCdnUrl;if(n.id.includes("/"))return n.isVideo?"".concat(t,"videos/").concat(n.id,"/original.mp4"):n.fileName?"".concat(a,"images/").concat(n.id,"/").concat(i,"/").concat(n.fileName,".webp"):"".concat(a,"images/").concat(n.id,"/image_").concat(i,".webp");var e=null===(o=c.merchantSettings)||void 0===o?void 0:o.merchantId;return n.isVideo?"".concat(t,"videos/").concat(e,"/").concat(n.id,"/original.mp4"):n.fileName?"".concat(a,"images/").concat(e,"/").concat(n.id,"/").concat(i,"/").concat(n.fileName,".webp"):"".concat(a,"images/").concat(e,"/").concat(n.id,"/image_").concat(i,".webp")}var a=[180,360,420,540,640,720,800,900,1080,1296,1350,1512,1728,1950,2560,3840];function t(c){return(null==c?void 0:c.id)?a.map(function(n){return"".concat(o(c,n)," ").concat(n,"w")}).join(", "):""}export{t as createMediaSrcset,n as getDefaultSrc,o as getSrc,i as getThumbnailSrc};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as t,__generator as n}from'./../../../ext/tslib/tslib.es6.mjs.js';import{IkasStorefrontConfig as r}from"../../../packages/storefront-config/src/index.js";import{CART_LS_KEY as e,cartStore as i}from"../../../stores/cart/index.js";import{customerStore as a}from"../../../stores/customer/index.js";import{getCookieValue as o}from"../../../utils/helper.js";import{getIkasOrderDistinctItemCount as s}from"../../models/order/index.js";import{getSelectedProductVariant as u,hasProductValidOptionValues as c}from"../../models/product/index.js";import{isProductOfferAccepted as d}from"../../models/product/campaign-offer/index.js";import{initProductOptionSetValues as l}from"../../models/product/option-set/index.js";import{hasProductVariantStock as f}from"../../models/product/variant/index.js";function v(t){var n,e=null===(n=t.cart)||void 0===n?void 0:n.id;if(e){var i=r.getCurrentRouting();return"".concat((null==i?void 0:i.path)?"/".concat(i.path):"","/checkout?id=").concat(e,"&step=info")}return""}function p(a,s){return t(this,arguments,void 0,function(t,a,s,d){var v,p,m,I,g,y,b,C,L,_,j,w,P,T,x,k,U;return void 0===s&&(s=1),n(this,function(n){switch(n.label){case 0:v=null!==(w=null==d?void 0:d.isPayWithIkas)&&void 0!==w&&w,n.label=1;case 1:return n.trys.push([1,10,,11]),v||!a.productOptionSetId||a.productOptionSet?c(a)?f(t)||t.sellIfOutOfStock?(p=void 0,v?[3,3]:[4,E()]):[2,{success:!1,validationError:"INSUFFICIENT_STOCK"}]:[2,{success:!1,validationError:"INVALID_PRODUCT_OPTION_VALUES"}]:[2,{success:!1,validationError:"INVALID_PRODUCT_OPTION_VALUES"}];case 2:if(n.sent(),i.cart&&(p=O(i.cart,t,a))){if(a.productOptionSet&&l(a.productOptionSet),!t.bundleSettings)return[2,h(p,p.quantity+s,a.offers,a)];if(!S())return[2,h(p,p.quantity+s,a.offers,a)]}n.label=3;case 3:return m=F(a),I=s,(null==(g=null===(P=a.salesChannels)||void 0===P?void 0:P.find(function(t){return t.id===r.salesChannelId}))?void 0:g.minQuantityPerCart)&&s<g.minQuantityPerCart&&(I=g.minQuantityPerCart),(null==g?void 0:g.maxQuantityPerCart)&&s>g.maxQuantityPerCart&&(I=g.maxQuantityPerCart),y=v?null:(null===(T=i.cart)||void 0===T?void 0:T.id)||localStorage.getItem(e),[4,import("../../api/cart/index.js")];case 4:return[4,(0,n.sent().apiAddItemToCart)({input:{cartId:y,item:{id:null!==(x=null==p?void 0:p.id)&&void 0!==x?x:null,quantity:null!==(k=null==p?void 0:p.quantity)&&void 0!==k?k:I,variant:{id:t.id,name:a.name,bundleProducts:null===(U=t.bundleSettings)||void 0===U?void 0:U.products.map(function(t){var n;return{id:t.id,productId:(null===(n=t.product)||void 0===n?void 0:n.id)||"",variantId:t.product?u(t.product).id:"",quantity:t.quantity}})}},acceptedOffers:q(a.offers),options:m.length?m:null,priceListId:r.priceListId||null,salesChannelId:r.salesChannelId,storefrontThemeId:r.storefrontThemeId,metadata:{_fbp:o("_fbp"),_fbc:o("_fbc")}}})];case 5:return b=n.sent(),v?[3,7]:b.isSuccess&&b.data?[4,A(b.data)]:[3,7];case 6:n.sent(),n.label=7;case 7:return(C=v?b.data:i.cart)?(L="".concat(C.id,"-").concat(C.updatedAt),(_=C.orderLineItems.find(function(n){return n.variant.id===t.id}))?[4,import("../../../analytics/analytics-functions/addToCart.js")]:[3,9]):[3,9];case 8:(0,n.sent().anl_addToCart)(_,s,L,C,a),n.label=9;case 9:return a.productOptionSet&&l(a.productOptionSet),[2,{success:b.isSuccess,response:b}];case 10:return j=n.sent(),console.log(j),[2,{success:!1}];case 11:return[2]}})})}function m(r){return t(this,arguments,void 0,function(t,r){return void 0===r&&(r=1),n(this,function(n){switch(n.label){case 0:return[4,p(u(t),t,r)];case 1:return[2,n.sent()]}})})}function h(e,a,s,u){return t(this,void 0,void 0,function(){var t,c,d,l,f,v;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,10,,11]),[4,E()];case 1:return n.sent(),[4,import("../../api/cart/index.js")];case 2:return[4,(0,n.sent().apiAddItemToCart)({input:{cartId:(null===(f=i.cart)||void 0===f?void 0:f.id)||null,item:{id:e.id,quantity:a,variant:{id:e.variant.id,name:e.variant.name,bundleProducts:null===(v=e.variant.bundleProducts)||void 0===v?void 0:v.map(function(t){return{id:t.id,productId:t.variant.productId||"",variantId:t.variant.id||"",quantity:t.quantity}})}},acceptedOffers:s?q(s):void 0,options:k(e),priceListId:r.priceListId||null,salesChannelId:r.salesChannelId,storefrontThemeId:r.storefrontThemeId,metadata:{_fbp:o("_fbp"),_fbc:o("_fbc")}}})];case 3:return(t=n.sent()).isSuccess&&t.data?[4,A(t.data)]:[3,5];case 4:n.sent(),n.label=5;case 5:return i.cart?(c="".concat(i.cart.id,"-").concat(i.cart.updatedAt),(d=e.quantity)>a?[4,import("../../../analytics/analytics-functions/removeFromCart.js")]:[3,7]):[3,9];case 6:return(0,n.sent().anl_removeFromCart)(e,d-a,i.cart),[3,9];case 7:return[4,import("../../../analytics/analytics-functions/addToCart.js")];case 8:(0,n.sent().anl_addToCart)(e,a-d,c,i.cart,u),n.label=9;case 9:return P(i),[2,{success:t.isSuccess,response:t}];case 10:return l=n.sent(),console.log(l),[2,{success:!1}];case 11:return[2]}})})}function I(r,e,i,a,o){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,h(e,i,a,o)];case 1:return[2,t.sent()]}})})}function g(t,n){for(var r=0,e=(null==t?void 0:t.orderAdjustments)||[];r<e.length;r++)for(var i=0,a=e[r].appliedOrderLines||[];i<a.length;i++){var o=a[i];if(o.orderLineId===n.id)return o.isAutoCreated||!1}return!1}function y(r){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,h(r,0)];case 1:return[2,t.sent()]}})})}function b(t){localStorage.removeItem(e),t.cart=null}function C(r){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,new Promise(function(t){var n=setInterval(function(){r.isCartInitialLoadFinished&&(clearInterval(n),t(null))},100)})];case 1:return[2,t.sent()]}})})}function S(){if("undefined"!=typeof window)return new URLSearchParams(window.location.search).get("editLineID")||""}function O(t,n,r){var e;if(!r.productOptionSetId&&!n.bundleSettings)return t.orderLineItems.find(function(t){return t.variant.id===n.id});if(n.bundleSettings){var i=S();if(i)if(h=t.orderLineItems.find(function(t){return t.id===i}))return h}var a=t.orderLineItems.filter(function(t){return t.variant.id===n.id})||[];if(r.productOptionSetId)for(var o=F(r),s=a.filter(function(t){var n;return(null===(n=t.options)||void 0===n?void 0:n.length)===o.length})||[],u=0,c=s;u<c.length;u++){if((h=c[u]).options){for(var d=!0,l=function(t){var n=t.values.map(function(t){return t.value}),r=null===(e=o.find(function(n){return n.productOptionId===t.productOptionId}))||void 0===e?void 0:e.values;if(!(d=d&&n.length===(null==r?void 0:r.length)&&n.every(function(t){return null==r?void 0:r.includes(t)})))return"break"},f=0,v=h.options;f<v.length;f++){if("break"===l(v[f]))break}if(d){if(!n.bundleSettings)return h;if(_(n,h))return h}}}else if(n.bundleSettings)for(var p=0,m=a;p<m.length;p++){var h=m[p];if(_(n,h))return h}}function L(t,n){return O(t,u(n),n)}function _(t,n){var r,e=null===(r=t.bundleSettings)||void 0===r?void 0:r.products,i=n.variant.bundleProducts;return!!e&&((null==e?void 0:e.length)===(null==i?void 0:i.length)&&(null==e?void 0:e.every(function(t){return!!(null==i?void 0:i.find(function(n){return n.id===t.id&&n.quantity===t.quantity&&t.product&&n.variant.id===u(t.product).id}))})))}function j(r,e){return t(this,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return[4,import("../../api/cart/index.js")];case 1:return[4,(0,n.sent().apiSaveCartCouponCode)({cartId:r.id,couponCode:e})];case 2:return(t=n.sent()).isSuccess&&t.data&&(i.cart=t.data),[2,{success:t.isSuccess,response:t}]}})})}function w(r){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,j(r,null)];case 1:return[2,t.sent()]}})})}function P(t){t.cart&&0===s(t.cart)&&b(t)}function T(){return t(this,void 0,void 0,function(){var t,r,o,s,u,c;return n(this,function(n){switch(n.label){case 0:if(!("undefined"!=typeof localStorage))return[2];n.label=1;case 1:return n.trys.push([1,7,8,9]),i.isCartLoading=!0,t=null===(u=a.customer)||void 0===u?void 0:u.id,(r=(null===(c=i.cart)||void 0===c?void 0:c.id)||localStorage.getItem(e))||t?[4,import("../../api/cart/index.js")]:[2];case 2:return[4,(0,n.sent().apiGetCartById)({id:r})];case 3:return(o=n.sent()).isSuccess&&o.data?[4,A(o.data)]:[3,5];case 4:return n.sent(),[3,6];case 5:if(o.isCancelled||o.isNetworkError)return[2];b(i),n.label=6;case 6:return[3,9];case 7:return s=n.sent(),console.log(s),[3,9];case 8:return i.isCartLoading=!1,i.isCartInitialLoadFinished=!0,[7];case 9:return[2]}})})}function q(t){var n=t.filter(function(t){return t.isSelected&&!d(t)}).map(function(t){return{campaignOfferId:t.campaignOfferId,campaignOfferProductId:t.campaignOfferProductId,productId:t.product.id,quantity:t.quantity,variantId:u(t.product).id}})||[];return n.length?n:void 0}function x(e,i){return t(this,arguments,void 0,function(t,e,i){var a,o,s,c,d,l,f,v,m,h,I,g,y,b,C;return void 0===i&&(i=1),n(this,function(t){switch(t.label){case 0:return t.trys.push([0,4,,5]),a=r.salesChannelId,o=r.storefrontThemeId,a&&o?(s=u(e))?[4,p(s,e,i,{isPayWithIkas:!0})]:[2,{success:!1,error:"No variant selected"}]:[2,{success:!1,error:"Missing storefront configuration"}];case 1:return(c=t.sent()).success&&(null===(m=null===(v=c.response)||void 0===v?void 0:v.data)||void 0===m?void 0:m.id)?(d=c.response.data.id,[4,import("../../api/cart/index.js")]):[2,{success:!1,error:(null===(g=null===(I=null===(h=c.response)||void 0===h?void 0:h.graphQLErrors)||void 0===I?void 0:I[0])||void 0===g?void 0:g.message)||"Failed to create cart"}];case 2:return[4,(0,t.sent().apiCreatePayWithIkasSessionUrl)({cartId:d})];case 3:return!(l=t.sent()).data||(null===(y=l.graphQLErrors)||void 0===y?void 0:y.length)?[2,{success:!1,error:(null===(C=null===(b=l.graphQLErrors)||void 0===b?void 0:b[0])||void 0===C?void 0:C.message)||"Failed to create Pay with ikas session"}]:[2,{success:!0,payUrl:l.data.payUrl,expiresAt:l.data.expiresAt}];case 4:return f=t.sent(),console.log("error",f),[2,{success:!1,error:f instanceof Error?f.message:"Unknown error occurred"}];case 5:return[2]}})})}function A(r){return t(this,void 0,void 0,function(){return n(this,function(t){return localStorage.setItem(e,r.id),i.cart=r,[2]})})}function E(){return t(this,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return t=localStorage.getItem(e),!i.cart||t?[3,1]:(b(i),[3,3]);case 1:return i.cart||!t?[3,3]:[4,T()];case 2:n.sent(),n.label=3;case 3:return[2]}})})}function k(t){if(t&&t.options){for(var n=[],r=0,e=t.options;r<e.length;r++){var i=e[r],a={productOptionId:i.productOptionId,productOptionsSetId:i.productOptionsSetId,values:i.values.map(function(t){return t.value})};n.push(a)}return n}return null}function F(t){var n,r=[],e=new Set,i=function(t){var n;e.has(t.id)||(e.add(t.id),t.values.length&&r.push({productOptionId:t.id,productOptionsSetId:t.productOptionSetId,values:t.values}),null===(n=t.childOptions)||void 0===n||n.forEach(i))};return null===(n=t.productOptionSet)||void 0===n||n.options.filter(function(t){return!t.requiredOptionId}).forEach(i),r}function U(e){return t(this,void 0,void 0,function(){var t,a,s,u,c,d,l,f,v,p,m;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,10,,11]),[4,E()];case 1:return n.sent(),t=e.itemId?null===(v=i.cart)||void 0===v?void 0:v.orderLineItems.find(function(t){return t.id===e.itemId}):null,[4,import("../../api/cart/index.js")];case 2:return[4,(0,n.sent().apiAddItemToCart)({input:{cartId:(null===(p=i.cart)||void 0===p?void 0:p.id)||null,item:{id:e.itemId||null,quantity:e.quantity,variant:{id:e.variantId}},priceListId:r.priceListId||null,salesChannelId:r.salesChannelId,storefrontThemeId:r.storefrontThemeId,metadata:{_fbp:o("_fbp"),_fbc:o("_fbc")}}})];case 3:return(a=n.sent()).isSuccess&&a.data?(e.itemId||(s=(null===(m=i.cart)||void 0===m?void 0:m.orderLineItems.map(function(t){return t.id}))||[],u=a.data.orderLineItems.map(function(t){return t.id}),(c=u.find(function(t){return!s.includes(t)}))&&(t=a.data.orderLineItems.find(function(t){return t.id===c}))),[4,A(a.data)]):[3,5];case 4:n.sent(),n.label=5;case 5:return i.cart&&t?(d="".concat(i.cart.id,"-").concat(i.cart.updatedAt),(l=e.quantity)>e.quantity?[4,import("../../../analytics/analytics-functions/removeFromCart.js")]:[3,7]):[3,9];case 6:return(0,n.sent().anl_removeFromCart)(t,l-e.quantity,i.cart),[3,9];case 7:return[4,import("../../../analytics/analytics-functions/addToCart.js")];case 8:(0,n.sent().anl_addToCart)(t,e.quantity-l,d,i.cart),n.label=9;case 9:return P(i),[2,{success:a.isSuccess,response:a}];case 10:return f=n.sent(),console.log(f),[2,{success:!1}];case 11:return[2]}})})}function Q(t){var n;return!!t.cart&&(null===(n=t.cart.orderLineItems)||void 0===n?void 0:n.length)>0}export{p as addItemToCart,m as addSelectedtedVariantToCart,I as changeCartItemQuantity,h as changeItemQuantity,x as createPayWithIkasSession,O as findExistingCartItem,L as findExistingCartItemWithProduct,q as getAcceptedOffers,T as getCart,v as getCheckoutUrlFromCartStore,Q as hasCart,g as isOrderLineItemAutoCreated,b as removeCart,w as removeCouponCode,y as removeItem,j as saveCouponCode,A as setCart,C as waitForCartStoreInit,U as windowAddToCart};
|
|
1
|
+
import{__awaiter as t,__generator as n}from'./../../../ext/tslib/tslib.es6.mjs.js';import{IkasStorefrontConfig as r}from"../../../packages/storefront-config/src/index.js";import{CART_LS_KEY as e,cartStore as i}from"../../../stores/cart/index.js";import{customerStore as a}from"../../../stores/customer/index.js";import{getCookieValue as o}from"../../../utils/helper.js";import{getIkasOrderDistinctItemCount as s}from"../../models/order/index.js";import{getSelectedProductVariant as u,hasProductValidOptionValues as c}from"../../models/product/index.js";import{isProductOfferAccepted as d}from"../../models/product/campaign-offer/index.js";import{initProductOptionSetValues as l}from"../../models/product/option-set/index.js";import{hasProductVariantStock as f}from"../../models/product/variant/index.js";import{waitForCustomerStoreInit as v}from"../customer/index.js";function p(t){var n,e=null===(n=t.cart)||void 0===n?void 0:n.id;if(e){var i=r.getCurrentRouting();return"".concat((null==i?void 0:i.path)?"/".concat(i.path):"","/checkout?id=").concat(e,"&step=info")}return""}function m(a,s){return t(this,arguments,void 0,function(t,a,s,d){var v,p,m,h,g,y,b,C,S,_,j,w,P,T,q,A,F;return void 0===s&&(s=1),n(this,function(n){switch(n.label){case 0:v=null!==(w=null==d?void 0:d.isPayWithIkas)&&void 0!==w&&w,n.label=1;case 1:return n.trys.push([1,10,,11]),v||!a.productOptionSetId||a.productOptionSet?c(a)?f(t)||t.sellIfOutOfStock?(p=void 0,v?[3,3]:[4,k()]):[2,{success:!1,validationError:"INSUFFICIENT_STOCK"}]:[2,{success:!1,validationError:"INVALID_PRODUCT_OPTION_VALUES"}]:[2,{success:!1,validationError:"INVALID_PRODUCT_OPTION_VALUES"}];case 2:if(n.sent(),i.cart&&(p=L(i.cart,t,a))){if(a.productOptionSet&&l(a.productOptionSet),!t.bundleSettings)return[2,I(p,p.quantity+s,a.offers,a)];if(!O())return[2,I(p,p.quantity+s,a.offers,a)]}n.label=3;case 3:return m=U(a),h=s,(null==(g=null===(P=a.salesChannels)||void 0===P?void 0:P.find(function(t){return t.id===r.salesChannelId}))?void 0:g.minQuantityPerCart)&&s<g.minQuantityPerCart&&(h=g.minQuantityPerCart),(null==g?void 0:g.maxQuantityPerCart)&&s>g.maxQuantityPerCart&&(h=g.maxQuantityPerCart),y=v?null:(null===(T=i.cart)||void 0===T?void 0:T.id)||localStorage.getItem(e),[4,import("../../api/cart/index.js")];case 4:return[4,(0,n.sent().apiAddItemToCart)({input:{cartId:y,item:{id:null!==(q=null==p?void 0:p.id)&&void 0!==q?q:null,quantity:null!==(A=null==p?void 0:p.quantity)&&void 0!==A?A:h,variant:{id:t.id,name:a.name,bundleProducts:null===(F=t.bundleSettings)||void 0===F?void 0:F.products.map(function(t){var n;return{id:t.id,productId:(null===(n=t.product)||void 0===n?void 0:n.id)||"",variantId:t.product?u(t.product).id:"",quantity:t.quantity}})}},acceptedOffers:x(a.offers),options:m.length?m:null,priceListId:r.priceListId||null,salesChannelId:r.salesChannelId,storefrontThemeId:r.storefrontThemeId,metadata:{_fbp:o("_fbp"),_fbc:o("_fbc")}}})];case 5:return b=n.sent(),v?[3,7]:b.isSuccess&&b.data?[4,E(b.data)]:[3,7];case 6:n.sent(),n.label=7;case 7:return(C=v?b.data:i.cart)?(S="".concat(C.id,"-").concat(C.updatedAt),(_=C.orderLineItems.find(function(n){return n.variant.id===t.id}))?[4,import("../../../analytics/analytics-functions/addToCart.js")]:[3,9]):[3,9];case 8:(0,n.sent().anl_addToCart)(_,s,S,C,a),n.label=9;case 9:return a.productOptionSet&&l(a.productOptionSet),[2,{success:b.isSuccess,response:b}];case 10:return j=n.sent(),console.log(j),[2,{success:!1}];case 11:return[2]}})})}function h(r){return t(this,arguments,void 0,function(t,r){return void 0===r&&(r=1),n(this,function(n){switch(n.label){case 0:return[4,m(u(t),t,r)];case 1:return[2,n.sent()]}})})}function I(e,a,s,u){return t(this,void 0,void 0,function(){var t,c,d,l,f,v;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,10,,11]),[4,k()];case 1:return n.sent(),[4,import("../../api/cart/index.js")];case 2:return[4,(0,n.sent().apiAddItemToCart)({input:{cartId:(null===(f=i.cart)||void 0===f?void 0:f.id)||null,item:{id:e.id,quantity:a,variant:{id:e.variant.id,name:e.variant.name,bundleProducts:null===(v=e.variant.bundleProducts)||void 0===v?void 0:v.map(function(t){return{id:t.id,productId:t.variant.productId||"",variantId:t.variant.id||"",quantity:t.quantity}})}},acceptedOffers:s?x(s):void 0,options:F(e),priceListId:r.priceListId||null,salesChannelId:r.salesChannelId,storefrontThemeId:r.storefrontThemeId,metadata:{_fbp:o("_fbp"),_fbc:o("_fbc")}}})];case 3:return(t=n.sent()).isSuccess&&t.data?[4,E(t.data)]:[3,5];case 4:n.sent(),n.label=5;case 5:return i.cart?(c="".concat(i.cart.id,"-").concat(i.cart.updatedAt),(d=e.quantity)>a?[4,import("../../../analytics/analytics-functions/removeFromCart.js")]:[3,7]):[3,9];case 6:return(0,n.sent().anl_removeFromCart)(e,d-a,i.cart),[3,9];case 7:return[4,import("../../../analytics/analytics-functions/addToCart.js")];case 8:(0,n.sent().anl_addToCart)(e,a-d,c,i.cart,u),n.label=9;case 9:return T(i),[2,{success:t.isSuccess,response:t}];case 10:return l=n.sent(),console.log(l),[2,{success:!1}];case 11:return[2]}})})}function g(r,e,i,a,o){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,I(e,i,a,o)];case 1:return[2,t.sent()]}})})}function y(t,n){for(var r=0,e=(null==t?void 0:t.orderAdjustments)||[];r<e.length;r++)for(var i=0,a=e[r].appliedOrderLines||[];i<a.length;i++){var o=a[i];if(o.orderLineId===n.id)return o.isAutoCreated||!1}return!1}function b(r){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,I(r,0)];case 1:return[2,t.sent()]}})})}function C(t){localStorage.removeItem(e),t.cart=null}function S(r){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,new Promise(function(t){var n=setInterval(function(){r.isCartInitialLoadFinished&&(clearInterval(n),t(null))},100)})];case 1:return[2,t.sent()]}})})}function O(){if("undefined"!=typeof window)return new URLSearchParams(window.location.search).get("editLineID")||""}function L(t,n,r){var e;if(!r.productOptionSetId&&!n.bundleSettings)return t.orderLineItems.find(function(t){return t.variant.id===n.id});if(n.bundleSettings){var i=O();if(i)if(h=t.orderLineItems.find(function(t){return t.id===i}))return h}var a=t.orderLineItems.filter(function(t){return t.variant.id===n.id})||[];if(r.productOptionSetId)for(var o=U(r),s=a.filter(function(t){var n;return(null===(n=t.options)||void 0===n?void 0:n.length)===o.length})||[],u=0,c=s;u<c.length;u++){if((h=c[u]).options){for(var d=!0,l=function(t){var n=t.values.map(function(t){return t.value}),r=null===(e=o.find(function(n){return n.productOptionId===t.productOptionId}))||void 0===e?void 0:e.values;if(!(d=d&&n.length===(null==r?void 0:r.length)&&n.every(function(t){return null==r?void 0:r.includes(t)})))return"break"},f=0,v=h.options;f<v.length;f++){if("break"===l(v[f]))break}if(d){if(!n.bundleSettings)return h;if(j(n,h))return h}}}else if(n.bundleSettings)for(var p=0,m=a;p<m.length;p++){var h=m[p];if(j(n,h))return h}}function _(t,n){return L(t,u(n),n)}function j(t,n){var r,e=null===(r=t.bundleSettings)||void 0===r?void 0:r.products,i=n.variant.bundleProducts;return!!e&&((null==e?void 0:e.length)===(null==i?void 0:i.length)&&(null==e?void 0:e.every(function(t){return!!(null==i?void 0:i.find(function(n){return n.id===t.id&&n.quantity===t.quantity&&t.product&&n.variant.id===u(t.product).id}))})))}function w(r,e){return t(this,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return[4,import("../../api/cart/index.js")];case 1:return[4,(0,n.sent().apiSaveCartCouponCode)({cartId:r.id,couponCode:e})];case 2:return(t=n.sent()).isSuccess&&t.data&&(i.cart=t.data),[2,{success:t.isSuccess,response:t}]}})})}function P(r){return t(this,void 0,void 0,function(){return n(this,function(t){switch(t.label){case 0:return[4,w(r,null)];case 1:return[2,t.sent()]}})})}function T(t){t.cart&&0===s(t.cart)&&C(t)}function q(){return t(this,void 0,void 0,function(){var t,r,o,s,u,c;return n(this,function(n){switch(n.label){case 0:if(!("undefined"!=typeof localStorage))return[2];n.label=1;case 1:return n.trys.push([1,8,9,10]),i.isCartLoading=!0,[4,v(a)];case 2:return n.sent(),t=null===(u=a.customer)||void 0===u?void 0:u.id,(r=(null===(c=i.cart)||void 0===c?void 0:c.id)||localStorage.getItem(e))||t?[4,import("../../api/cart/index.js")]:[2];case 3:return[4,(0,n.sent().apiGetCartById)({id:r})];case 4:return(o=n.sent()).isSuccess&&o.data?[4,E(o.data)]:[3,6];case 5:return n.sent(),[3,7];case 6:if(o.isCancelled||o.isNetworkError)return[2];C(i),n.label=7;case 7:return[3,10];case 8:return s=n.sent(),console.log(s),[3,10];case 9:return i.isCartLoading=!1,i.isCartInitialLoadFinished=!0,[7];case 10:return[2]}})})}function x(t){var n=t.filter(function(t){return t.isSelected&&!d(t)}).map(function(t){return{campaignOfferId:t.campaignOfferId,campaignOfferProductId:t.campaignOfferProductId,productId:t.product.id,quantity:t.quantity,variantId:u(t.product).id}})||[];return n.length?n:void 0}function A(e,i){return t(this,arguments,void 0,function(t,e,i){var a,o,s,c,d,l,f,v,p,h,I,g,y,b,C;return void 0===i&&(i=1),n(this,function(t){switch(t.label){case 0:return t.trys.push([0,4,,5]),a=r.salesChannelId,o=r.storefrontThemeId,a&&o?(s=u(e))?[4,m(s,e,i,{isPayWithIkas:!0})]:[2,{success:!1,error:"No variant selected"}]:[2,{success:!1,error:"Missing storefront configuration"}];case 1:return(c=t.sent()).success&&(null===(p=null===(v=c.response)||void 0===v?void 0:v.data)||void 0===p?void 0:p.id)?(d=c.response.data.id,[4,import("../../api/cart/index.js")]):[2,{success:!1,error:(null===(g=null===(I=null===(h=c.response)||void 0===h?void 0:h.graphQLErrors)||void 0===I?void 0:I[0])||void 0===g?void 0:g.message)||"Failed to create cart"}];case 2:return[4,(0,t.sent().apiCreatePayWithIkasSessionUrl)({cartId:d})];case 3:return!(l=t.sent()).data||(null===(y=l.graphQLErrors)||void 0===y?void 0:y.length)?[2,{success:!1,error:(null===(C=null===(b=l.graphQLErrors)||void 0===b?void 0:b[0])||void 0===C?void 0:C.message)||"Failed to create Pay with ikas session"}]:[2,{success:!0,payUrl:l.data.payUrl,expiresAt:l.data.expiresAt}];case 4:return f=t.sent(),console.log("error",f),[2,{success:!1,error:f instanceof Error?f.message:"Unknown error occurred"}];case 5:return[2]}})})}function E(r){return t(this,void 0,void 0,function(){return n(this,function(t){return localStorage.setItem(e,r.id),i.cart=r,[2]})})}function k(){return t(this,void 0,void 0,function(){var t;return n(this,function(n){switch(n.label){case 0:return t=localStorage.getItem(e),!i.cart||t?[3,1]:(C(i),[3,3]);case 1:return i.cart||!t?[3,3]:[4,q()];case 2:n.sent(),n.label=3;case 3:return[2]}})})}function F(t){if(t&&t.options){for(var n=[],r=0,e=t.options;r<e.length;r++){var i=e[r],a={productOptionId:i.productOptionId,productOptionsSetId:i.productOptionsSetId,values:i.values.map(function(t){return t.value})};n.push(a)}return n}return null}function U(t){var n,r=[],e=new Set,i=function(t){var n;e.has(t.id)||(e.add(t.id),t.values.length&&r.push({productOptionId:t.id,productOptionsSetId:t.productOptionSetId,values:t.values}),null===(n=t.childOptions)||void 0===n||n.forEach(i))};return null===(n=t.productOptionSet)||void 0===n||n.options.filter(function(t){return!t.requiredOptionId}).forEach(i),r}function Q(e){return t(this,void 0,void 0,function(){var t,a,s,u,c,d,l,f,v,p,m;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,10,,11]),[4,k()];case 1:return n.sent(),t=e.itemId?null===(v=i.cart)||void 0===v?void 0:v.orderLineItems.find(function(t){return t.id===e.itemId}):null,[4,import("../../api/cart/index.js")];case 2:return[4,(0,n.sent().apiAddItemToCart)({input:{cartId:(null===(p=i.cart)||void 0===p?void 0:p.id)||null,item:{id:e.itemId||null,quantity:e.quantity,variant:{id:e.variantId}},priceListId:r.priceListId||null,salesChannelId:r.salesChannelId,storefrontThemeId:r.storefrontThemeId,metadata:{_fbp:o("_fbp"),_fbc:o("_fbc")}}})];case 3:return(a=n.sent()).isSuccess&&a.data?(e.itemId||(s=(null===(m=i.cart)||void 0===m?void 0:m.orderLineItems.map(function(t){return t.id}))||[],u=a.data.orderLineItems.map(function(t){return t.id}),(c=u.find(function(t){return!s.includes(t)}))&&(t=a.data.orderLineItems.find(function(t){return t.id===c}))),[4,E(a.data)]):[3,5];case 4:n.sent(),n.label=5;case 5:return i.cart&&t?(d="".concat(i.cart.id,"-").concat(i.cart.updatedAt),(l=e.quantity)>e.quantity?[4,import("../../../analytics/analytics-functions/removeFromCart.js")]:[3,7]):[3,9];case 6:return(0,n.sent().anl_removeFromCart)(t,l-e.quantity,i.cart),[3,9];case 7:return[4,import("../../../analytics/analytics-functions/addToCart.js")];case 8:(0,n.sent().anl_addToCart)(t,e.quantity-l,d,i.cart),n.label=9;case 9:return T(i),[2,{success:a.isSuccess,response:a}];case 10:return f=n.sent(),console.log(f),[2,{success:!1}];case 11:return[2]}})})}function N(t){var n;return!!t.cart&&(null===(n=t.cart.orderLineItems)||void 0===n?void 0:n.length)>0}export{m as addItemToCart,h as addSelectedtedVariantToCart,g as changeCartItemQuantity,I as changeItemQuantity,A as createPayWithIkasSession,L as findExistingCartItem,_ as findExistingCartItemWithProduct,x as getAcceptedOffers,q as getCart,p as getCheckoutUrlFromCartStore,N as hasCart,y as isOrderLineItemAutoCreated,C as removeCart,P as removeCouponCode,b as removeItem,w as saveCouponCode,E as setCart,S as waitForCartStoreInit,Q as windowAddToCart};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__assign as r}from'./../ext/tslib/tslib.es6.mjs.js';import{createElement as t}from'./../ext/preact/dist/preact.mjs.js';import{useRef as n,
|
|
1
|
+
import{__assign as r}from'./../ext/tslib/tslib.es6.mjs.js';import{createElement as t}from'./../ext/preact/dist/preact.mjs.js';import{useRef as n,useMemo as e,useEffect as o}from'./../ext/preact/hooks/dist/hooks.mjs.js';var c={};function a(r,t){for(var n=[],e=r;e;){var o=e.getAttribute("id");o&&n.unshift(o),e=e.parentElement}var c=n.map(function(r){return'[id="'.concat(r,'"]')}).join(" ");return c?"".concat(c,' [id="').concat(t,'"]'):'[id="'.concat(t,'"]')}function u(u){var i=u.id,s=u.components,f=u.style,l=u.className,m=u.parentProps,d=void 0===m?c:m,p=u.map,v=void 0===p?c:p,h=n([]),y=n(d),j=n(v),g=n(null);y.current=d,j.current=v;var E=e(function(){return(Array.isArray(s)?s:s?[s]:[]).flat().filter(Boolean)},[s]);o(function(){if(0!==E.length){h.current.forEach(function(r){return r()}),h.current=[];for(var t=0;t<E.length;t++){var n=E[t];if(n.l){var e="".concat(i,"-").concat(t),o=a(g.current,e),c=n.l(o,r(r({},y.current),j.current),{},{id:e,key:e});"function"==typeof c&&h.current.push(c)}}return function(){h.current.forEach(function(r){return r()}),h.current=[]}}},[E,i]);var _=e(function(){return 0===E.length?"":E.map(function(t,n){var e="".concat(i,"-").concat(n);return t.r(r(r({},y.current),j.current),{},{id:e,key:e})}).join("")},[E,i]);return 0===E.length?null:t("div",{id:i,ref:g,dangerouslySetInnerHTML:{__html:_},style:r({display:"contents"},f),className:l})}export{u as IkasComponentRenderer};
|