@ikas/storefront 6.1.0-beta.221 → 6.1.0-beta.223
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.
- package/build/analytics/analytics.d.ts +3 -0
- package/build/analytics/analytics.js +1 -1
- package/build/analytics/events.d.ts +4 -1
- package/build/analytics/events.js +1 -1
- package/build/analytics/googleTagManager.js +1 -1
- package/build/components/checkout/components/cart-summary/index.js +1 -1
- package/build/components/checkout/model.d.ts +1 -1
- package/build/components/checkout/model.js +1 -1
- package/build/components/index.d.ts +1 -0
- package/build/components/page/head.js +1 -1
- package/build/components/page-editor/model.js +1 -1
- package/build/components/pay-with-ikas/index.d.ts +8 -0
- package/build/components/pay-with-ikas/index.js +1 -0
- package/build/hooks/useStore.js +1 -1
- package/build/index.js +1 -1
- package/build/models/ui/product-list/index.js +1 -1
- package/build/pages/checkout.js +1 -1
- package/build/store/cart/api.d.ts +2 -1
- package/build/store/cart/api.js +1 -1
- package/build/store/cart/index.d.ts +23 -1
- package/build/store/cart/index.js +1 -1
- package/build/store/index.d.ts +1 -0
- package/package.json +11 -11
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AddItemToCartQueryParams, GetCartByIdQueryParams, SaveCartCouponCodeQueryParams, SaveCartQueryParams, UpdateCartCampaignOfferQueryParams, CreateCartQueryParams, RemoveGiftCardFromCartQueryParams, RemoveLoyaltyPointsFromCartQueryParams } from "@ikas/storefront-api";
|
|
1
|
+
import { AddItemToCartQueryParams, GetCartByIdQueryParams, SaveCartCouponCodeQueryParams, SaveCartQueryParams, UpdateCartCampaignOfferQueryParams, CreateCartQueryParams, RemoveGiftCardFromCartQueryParams, RemoveLoyaltyPointsFromCartQueryParams, CreatePayWithIkasSessionUrlQueryParams } from "@ikas/storefront-api";
|
|
2
2
|
import { APIResponse } from "@ikas/fe-api-client";
|
|
3
3
|
import { IkasCart } from "../../models/data/cart";
|
|
4
4
|
export default class CartStoreAPI {
|
|
@@ -10,4 +10,5 @@ export default class CartStoreAPI {
|
|
|
10
10
|
static addItemToCart: (params: AddItemToCartQueryParams) => Promise<APIResponse<IkasCart | null>>;
|
|
11
11
|
static updateCartCampaignOffer: (params: UpdateCartCampaignOfferQueryParams) => Promise<APIResponse<IkasCart | null>>;
|
|
12
12
|
static createCart: (params: CreateCartQueryParams) => Promise<APIResponse<IkasCart | null>>;
|
|
13
|
+
static createPayWithIkasSessionUrl: (params: CreatePayWithIkasSessionUrlQueryParams) => Promise<APIResponse<import("@ikas/storefront-api/build/__api/types").CreatePayWithIkasSessionUrlResponse | null>>;
|
|
13
14
|
}
|
package/build/store/cart/api.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as r,__generator as n}from'./../../ext/tslib/tslib.es6.js';import{getCartById as t,saveCart as e,saveCartCouponCode as a,removeGiftCardFromCart as o,removeLoyaltyPointsFromCart as i,addItemToCart as u,updateCartCampaignOffer as s,createCart as d}from"@ikas/storefront-api";import{APIResponse as l}from'./../../ext/@ikas/fe-api-client/build/utils/api.js';import'./../../ext/axios/index.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_defineProperty.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseGetTag.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_stringToPath.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseToString.js';import{IkasCart as
|
|
1
|
+
import{__awaiter as r,__generator as n}from'./../../ext/tslib/tslib.es6.js';import{getCartById as t,saveCart as e,saveCartCouponCode as a,removeGiftCardFromCart as o,removeLoyaltyPointsFromCart as i,addItemToCart as u,updateCartCampaignOffer as s,createCart as d,createPayWithIkasSessionUrl as c}from"@ikas/storefront-api";import{APIResponse as l}from'./../../ext/@ikas/fe-api-client/build/utils/api.js';import'./../../ext/axios/index.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_defineProperty.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseGetTag.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_stringToPath.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseToString.js';import{IkasCart as f}from"../../models/data/cart/index.js";var v=function(){function v(){}var p;return p=v,v.getCartById=function(e){return r(void 0,void 0,void 0,(function(){var r;return n(p,(function(n){switch(n.label){case 0:return[4,t(e)];case 1:return r=n.sent(),[2,new l(r.data?new f(r.data):null,r.graphQLErrors)]}}))}))},v.saveCart=function(t){return r(void 0,void 0,void 0,(function(){var r;return n(p,(function(n){switch(n.label){case 0:return[4,e(t)];case 1:return r=n.sent(),[2,new l(r.data?new f(r.data):null,r.graphQLErrors)]}}))}))},v.saveCartCouponCode=function(t){return r(void 0,void 0,void 0,(function(){var r;return n(p,(function(n){switch(n.label){case 0:return[4,a(t)];case 1:return r=n.sent(),[2,new l(r.data?new f(r.data):null,r.graphQLErrors)]}}))}))},v.removeGiftCardFromCart=function(t){return r(void 0,void 0,void 0,(function(){var r;return n(p,(function(n){switch(n.label){case 0:return[4,o(t)];case 1:return r=n.sent(),[2,new l(r.data?new f(r.data):null,r.graphQLErrors)]}}))}))},v.removeLoyaltyPointsFromCart=function(t){return r(void 0,void 0,void 0,(function(){var r;return n(p,(function(n){switch(n.label){case 0:return[4,i(t)];case 1:return r=n.sent(),[2,new l(r.data?new f(r.data):null,r.graphQLErrors)]}}))}))},v.addItemToCart=function(t){return r(void 0,void 0,void 0,(function(){var r;return n(p,(function(n){switch(n.label){case 0:return[4,u(t)];case 1:return r=n.sent(),[2,new l(r.data?new f(r.data):null,r.graphQLErrors)]}}))}))},v.updateCartCampaignOffer=function(t){return r(void 0,void 0,void 0,(function(){var r;return n(p,(function(n){switch(n.label){case 0:return[4,s(t)];case 1:return r=n.sent(),[2,new l(r.data?new f(r.data):null,r.graphQLErrors)]}}))}))},v.createCart=function(t){return r(void 0,void 0,void 0,(function(){var r;return n(p,(function(n){switch(n.label){case 0:return[4,d(t)];case 1:return r=n.sent(),[2,new l(r.data?new f(r.data):null,r.graphQLErrors)]}}))}))},v.createPayWithIkasSessionUrl=function(t){return r(void 0,void 0,void 0,(function(){var r;return n(p,(function(n){switch(n.label){case 0:return[4,c(t)];case 1:return r=n.sent(),[2,new l(r.data?r.data:null,r.graphQLErrors)]}}))}))},v}();export{v as default};
|
|
@@ -13,7 +13,7 @@ export declare class IkasCartStore {
|
|
|
13
13
|
get isCartLoadFinished(): boolean;
|
|
14
14
|
get checkoutId(): string | undefined;
|
|
15
15
|
get checkoutUrl(): string | undefined;
|
|
16
|
-
addItem: (variant: IkasProductVariant, product: IkasProduct, initialQuantity?: number) => Promise<IkasCartOperationResult>;
|
|
16
|
+
addItem: (variant: IkasProductVariant, product: IkasProduct, initialQuantity?: number, options?: AddItemOptions) => Promise<IkasCartOperationResult>;
|
|
17
17
|
changeItemQuantity: (item: IkasOrderLineItem, quantity: number, campaignOffers?: IkasProductOffer[], product?: IkasProduct) => Promise<IkasCartOperationResult>;
|
|
18
18
|
createCart: (params: ICartCreateParams) => Promise<{
|
|
19
19
|
success: boolean;
|
|
@@ -33,6 +33,15 @@ export declare class IkasCartStore {
|
|
|
33
33
|
private removeCardIfEmpty;
|
|
34
34
|
getCart: () => Promise<void>;
|
|
35
35
|
private getAcceptedOffers;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new temporary cart with the given product and initiates a Pay with ikas session.
|
|
38
|
+
* This does not affect the user's current cart in localStorage or the CartStore.
|
|
39
|
+
*
|
|
40
|
+
* @param product - The product to purchase via fast checkout
|
|
41
|
+
* @param quantity - The quantity to purchase (defaults to 1)
|
|
42
|
+
* @returns PayWithIkasResult with the session URL or error
|
|
43
|
+
*/
|
|
44
|
+
createPayWithIkasSession(product: IkasProduct, quantity?: number): Promise<PayWithIkasResult>;
|
|
36
45
|
private setCart;
|
|
37
46
|
private beforeCartOperationCheck;
|
|
38
47
|
private createCartLineOptions;
|
|
@@ -49,3 +58,16 @@ export declare enum IkasCartOperationValidationError {
|
|
|
49
58
|
INVALID_PRODUCT_OPTION_VALUES = "INVALID_PRODUCT_OPTION_VALUES",
|
|
50
59
|
EMPTY_CART = "EMPTY_CART"
|
|
51
60
|
}
|
|
61
|
+
export declare type AddItemOptions = {
|
|
62
|
+
/**
|
|
63
|
+
* When true, skips localStorage operations, existing item lookup, and analytics.
|
|
64
|
+
* Used for Pay with ikas flow to create a temporary cart without affecting the user's cart.
|
|
65
|
+
*/
|
|
66
|
+
isPayWithIkas?: boolean;
|
|
67
|
+
};
|
|
68
|
+
export declare type PayWithIkasResult = {
|
|
69
|
+
success: boolean;
|
|
70
|
+
payUrl?: string;
|
|
71
|
+
expiresAt?: number;
|
|
72
|
+
error?: string;
|
|
73
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as t,__generator as e,__assign as i}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as r}from"mobx";import n from"./api.js";import"../../models/data/blog/category/index.js";import"../../models/data/blog/content/index.js";import"../../models/data/blog/meta-data/index.js";import"../../models/data/blog/tag/index.js";import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import{IkasProductOptionType as a,IkasCustomerEmailSubscriptionStatus as o}from"@ikas/storefront-models";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import"../../models/data/checkout/index.js";import"../../models/data/checkout-settings/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import"../../models/data/customer/address/region/index.js";import"../../models/data/customer/address/index.js";import"../../models/data/customer/address/ikas-localized-customer-address.js";import"../../models/data/customer/attribute/index.js";import"../../models/data/customer/review/summary/index.js";import"../../models/data/customer/review/index.js";import"../../models/data/customer/index.js";import"../../models/data/customer-form-data-input/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/filter-category/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import"../../models/data/order/address/region/index.js";import"../../models/data/order/address/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/variant/value/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/order-transaction-with-prices/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/payment-gateway/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product/filter/index.js";import"../../models/data/product/campaign-offer/index.js";import"../../models/data/product/option-set/option/index.js";import"../../models/data/product/option-set/index.js";import"../../models/data/product/stock-location/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/variant-type/index.js";import"../../models/data/product/index.js";import"../../models/data/raffle/index.js";import"../../models/data/shipping-zone/state/city/district/region/index.js";import"../../models/data/state/index.js";import"../../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../../models/data/storefront-popup/storefront-popup-page-filter/index.js";import"../../models/data/storefront-popup/index.js";import"../../models/data/theme-json/index.js";import"../../models/data/theme-json/component/index.js";import"../../models/data/theme-json/custom-data/index.js";import"../../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import{IkasStorefrontConfig as s}from"@ikas/storefront-config";import{Analytics as d}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{SaveCartInput as u}from"@ikas/storefront-api";import{getCookieValue as c}from"../../utils/helper.js";var l,p="cartId",m=function(){function p(p){var m=this;this.cart=null,this._isLoadingCart=!1,this._isCartLoadFinished=!1,this.addItem=function(r,a,o){return void 0===o&&(o=1),t(m,void 0,void 0,(function(){var t,u,p,m,f,v,h,I,g,C,b,S,y,j,x,O,P;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),a.productOptionSetId&&!a.productOptionSet&&this.baseStore.router?(this.baseStore.router.push(a.productHref),[2,{success:!1,validationError:l.INVALID_PRODUCT_OPTION_VALUES}]):a.hasValidProductOptionValues?r.hasStock||r.sellIfOutOfStock?[4,this.beforeCartOperationCheck()]:[2,{success:!1,validationError:l.INSUFFICIENT_STOCK}]:[2,{success:!1,validationError:l.INVALID_PRODUCT_OPTION_VALUES}];case 1:if(e.sent(),t=void 0,this.cart&&(t=this.findExistingItem(r,a))){if(null===(C=a.productOptionSet)||void 0===C||C.initOptionValues(),!r.bundleSettings)return[2,this.changeItemQuantity(t,t.quantity+1,a.offers,a)];if(!this.getEditLineID())return[2,this.changeItemQuantity(t,t.quantity+1,a.offers,a)]}return u=this.getOptionValues(a),p=o,(null==(m=null===(b=a.salesChannels)||void 0===b?void 0:b.find((function(t){return t.id===s.getSalesChannelId()})))?void 0:m.minQuantityPerCart)&&o<m.minQuantityPerCart&&(p=m.minQuantityPerCart),(null==m?void 0:m.maxQuantityPerCart)&&o>m.maxQuantityPerCart&&(p=m.maxQuantityPerCart),f=(null===(S=this.cart)||void 0===S?void 0:S.id)||localStorage.getItem("cartId"),[4,n.addItemToCart({input:i({cartId:f,item:{id:null!==(y=null==t?void 0:t.id)&&void 0!==y?y:null,quantity:null!==(j=null==t?void 0:t.quantity)&&void 0!==j?j:p,variant:{id:r.id,name:a.name,bundleProducts:null===(x=r.bundleSettings)||void 0===x?void 0:x.products.map((function(t){var e,i,r;return{id:t.id,productId:(null===(e=t.product)||void 0===e?void 0:e.id)||"",variantId:(null===(r=null===(i=t.product)||void 0===i?void 0:i.selectedVariant)||void 0===r?void 0:r.id)||"",quantity:t.quantity}}))}},acceptedOffers:this.getAcceptedOffers(a.offers),options:u.length?u:null,priceListId:s.getPriceListId()||null,salesChannelId:s.getSalesChannelId(),storefrontThemeId:s.getStorefrontThemeId(),metadata:{_fbp:c("_fbp"),_fbc:c("_fbc"),_ga:c("_ga")}},a.selectedVariant.subscriptionPlan&&a.selectedVariant.subscriptionPlan.isSelected?{subscriptionPlanId:a.selectedVariant.subscriptionPlan.subscriptionPlanId,subscriptionPlanPeriodId:null===(O=a.selectedVariant.subscriptionPlan.periods.find((function(t){return t.isSelected})))||void 0===O?void 0:O.id}:{})})];case 2:return(v=e.sent()).isSuccess&&v.data?[4,this.setCart(v.data)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.cart&&(h="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(I=this.cart.items.find((function(t){return t.variant.id===r.id})))&&d.addToCart(I,o,h,this.cart,a)),null===(P=a.productOptionSet)||void 0===P||P.initOptionValues(),[2,{success:v.isSuccess,response:v}];case 5:return g=e.sent(),console.log(g),[2,{success:!1}];case 6:return[2]}}))}))},this.changeItemQuantity=function(r,a,o,u){return t(m,void 0,void 0,(function(){var t,l,p,m,f,v,h,I,g;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),[4,this.beforeCartOperationCheck()];case 1:return e.sent(),[4,n.addItemToCart({input:i({cartId:(null===(f=this.cart)||void 0===f?void 0:f.id)||null,item:{id:r.id,quantity:a,variant:{id:r.variant.id,name:r.variant.name,bundleProducts:null===(v=r.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:this.getAcceptedOffers(o),options:this.createCartLineOptions(r),priceListId:s.getPriceListId()||null,salesChannelId:s.getSalesChannelId(),storefrontThemeId:s.getStorefrontThemeId(),metadata:{_fbp:c("_fbp"),_fbc:c("_fbc"),_ga:c("_ga")}},(null===(h=null==u?void 0:u.selectedVariant)||void 0===h?void 0:h.subscriptionPlan)&&(null===(I=null==u?void 0:u.selectedVariant)||void 0===I?void 0:I.subscriptionPlan.isSelected)?{subscriptionPlanId:null==u?void 0:u.selectedVariant.subscriptionPlan.subscriptionPlanId,subscriptionPlanPeriodId:null===(g=null==u?void 0:u.selectedVariant.subscriptionPlan.periods.find((function(t){return t.isSelected})))||void 0===g?void 0:g.id}:{})})];case 2:return(t=e.sent()).isSuccess&&t.data?[4,this.setCart(t.data)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.cart&&(l="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(p=r.quantity)>a?d.removeFromCart(r,p-a,this.cart):d.addToCart(r,a-p,l,this.cart,u)),this.removeCardIfEmpty(),[2,{success:t.isSuccess,response:t}];case 5:return m=e.sent(),console.log(m),[2,{success:!1}];case 6:return[2]}}))}))},this.createCart=function(i){return t(m,void 0,void 0,(function(){var t,r=this;return e(this,(function(e){switch(e.label){case 0:return[4,n.createCart({input:{items:i.variantLines.map((function(t){return{variant:{id:t.variantId},quantity:t.quantity}})),couponCode:i.couponCode,salesChannelId:s.getSalesChannelId(),storefrontThemeId:s.getStorefrontThemeId()}})];case 1:return(t=e.sent()).isSuccess&&t.data?[4,this.setCart(t.data)]:[3,3];case 2:e.sent(),e.label=3;case 3:return i.variantLines.forEach((function(t){if(r.cart){var e="".concat(r.cart.id,"-").concat(r.cart.updatedAt),i=r.cart.items.find((function(e){return e.variant.id===t.variantId}));i&&d.addToCart(i,t.quantity,e,r.cart)}})),[2,{success:t.isSuccess,response:t}]}}))}))},this.removeItem=function(i){return t(m,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.changeItemQuantity(i,0)];case 1:return[2,t.sent()]}}))}))},this.removeCart=function(){localStorage.removeItem("cartId"),m.cart=void 0},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){m.isCartLoadFinished&&(clearInterval(e),t(null))}),100)}))},this.getEditLineID=function(){if("undefined"!=typeof window)return new URLSearchParams(window.location.search).get("editLineID")||""},this.findExistingItem=function(t,e){var i,r,n,a,o,s;if(!e.productOptionSetId&&!t.bundleSettings)return null===(i=m.cart)||void 0===i?void 0:i.orderLineItems.find((function(e){return e.variant.id===t.id}));if(t.bundleSettings){var d=m.getEditLineID();if(d)if(S=null===(r=m.cart)||void 0===r?void 0:r.orderLineItems.find((function(t){return t.id===d})))return S}var u=(null===(n=m.cart)||void 0===n?void 0:n.orderLineItems.filter((function(e){return e.variant.id===t.id})))||[];if(e.productOptionSetId)for(var c=m.getOptionValues(e),l=u.filter((function(t){var e;return(null===(e=t.options)||void 0===e?void 0:e.length)===c.length}))||[],p=0,f=l;p<f.length;p++){if((S=f[p]).options){for(var v=!0,h=function(t){var i=t.values.map((function(t){return t.value})),r=null===(s=null===(o=null===(a=e.productOptionSet)||void 0===a?void 0:a.options)||void 0===o?void 0:o.find((function(e){return e.id===t.productOptionId})))||void 0===s?void 0:s.values;if(!(v=v&&i.length===(null==r?void 0:r.length)&&i.every((function(t){return null==r?void 0:r.includes(t)}))))return"break"},I=0,g=S.options;I<g.length;I++){if("break"===h(g[I]))break}if(v){if(!t.bundleSettings)return S;if(m.isSameBundleItem(t,S))return S}}}else if(t.bundleSettings)for(var C=0,b=u;C<b.length;C++){var S=b[C];if(m.isSameBundleItem(t,S))return S}},this.isSameBundleItem=function(t,e){var i,r=null===(i=t.bundleSettings)||void 0===i?void 0:i.products,n=e.variant.bundleProducts;return!!r&&((null==r?void 0:r.length)===(null==n?void 0:n.length)&&(null==r?void 0:r.every((function(t){return!!(null==n?void 0:n.find((function(e){var i;return e.id===t.id&&e.quantity===t.quantity&&e.variant.id===(null===(i=t.product)||void 0===i?void 0:i.selectedVariant.id)})))}))))},this.saveCouponCode=function(i){return t(m,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.cart?[4,n.saveCartCouponCode({cartId:this.cart.id,couponCode:i})]:[2,{success:!1,validationError:l.EMPTY_CART}];case 1:return(t=e.sent()).isSuccess&&t.data&&(this.cart=t.data),[2,{success:t.isSuccess,response:t}]}}))}))},this.removeCouponCode=function(){return t(m,void 0,void 0,(function(){return e(this,(function(t){return[2,this.saveCouponCode(null)]}))}))},this.removeGiftCardLine=function(i){return t(m,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.cart?[4,n.removeGiftCardFromCart({cartId:this.cart.id,giftCardId:i})]:[2,{success:!1,validationError:l.EMPTY_CART}];case 1:return(t=e.sent()).isSuccess&&t.data&&(this.cart=t.data),[2,{success:t.isSuccess,response:t}]}}))}))},this.removeLoyaltyPointsFromCart=function(i){return t(m,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.cart?[4,n.removeLoyaltyPointsFromCart({cartId:this.cart.id,loyaltySpendingMethodId:i})]:[2,{success:!1,validationError:l.EMPTY_CART}];case 1:return(t=e.sent()).isSuccess&&t.data&&(this.cart=t.data),[2,{success:t.isSuccess,response:t}]}}))}))},this.saveCart=function(i){return t(m,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return(t=new u(i)).customer&&this.baseStore.customerStore.customer&&(t.customer.notificationsAccepted=this.baseStore.customerStore.customer.subscriptionStatus===o.SUBSCRIBED),[4,n.saveCart({input:t})];case 1:return[2,{success:(r=e.sent()).isSuccess,response:r}]}}))}))},this.removeCardIfEmpty=function(){var t;0===(null===(t=m.cart)||void 0===t?void 0:t.itemCount)&&m.removeCart()},this.getCart=function(){return t(m,void 0,void 0,(function(){var t,i,r,a,o,s;return e(this,(function(e){switch(e.label){case 0:if(!("undefined"!=typeof localStorage))return[2];e.label=1;case 1:return e.trys.push([1,6,7,8]),this._isLoadingCart=!0,t=null===(o=this.baseStore.customerStore.customer)||void 0===o?void 0:o.id,(i=(null===(s=this.cart)||void 0===s?void 0:s.id)||localStorage.getItem("cartId"))||t?[4,n.getCartById({id:i})]:[2];case 2:return(r=e.sent()).isSuccess&&r.data?[4,this.setCart(r.data)]:[3,4];case 3:return e.sent(),[3,5];case 4:this.removeCart(),e.label=5;case 5:return[3,8];case 6:return a=e.sent(),console.log(a),[3,8];case 7:return this._isLoadingCart=!1,this._isCartLoadFinished=!0,[7];case 8:return[2]}}))}))},this.setCart=function(i){return t(m,void 0,void 0,(function(){return e(this,(function(t){return localStorage.setItem("cartId",i.id),this.cart=i,[2]}))}))},this.beforeCartOperationCheck=function(){return t(m,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return t=localStorage.getItem("cartId"),!this.cart||t?[3,1]:(this.removeCart(),[3,3]);case 1:return this.cart||!t?[3,3]:[4,this.getCart()];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},this.createCartLineOptions=function(t){if(t&&t.options){for(var e=[],i=0,r=t.options;i<r.length;i++){var n=r[i],a={productOptionId:n.productOptionId,productOptionsSetId:n.productOptionsSetId,values:n.values.map((function(t){return t.value}))};e.push(a)}return e}return null},this.getOptionValues=function(t){var e,i=[];return null===(e=t.productOptionSet)||void 0===e||e.options.forEach((function(t){var e=t.values;t.type===a.DATE_PICKER&&(e=t.values.map((function(t){var e=new Date(t);return isNaN(e.getTime())?t:e.toISOString().split("T")[0]}))),t.values.length&&i.push({productOptionId:t.id,productOptionsSetId:t.productOptionSetId,values:e})})),i},this._windowAddToCart=function(i){return t(m,void 0,void 0,(function(){var t,r,a,o,u,l,p,m,f,v,h;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),[4,this.beforeCartOperationCheck()];case 1:return e.sent(),t=i.itemId?null===(f=this.cart)||void 0===f?void 0:f.items.find((function(t){return t.id===i.itemId})):null,[4,n.addItemToCart({input:{cartId:(null===(v=this.cart)||void 0===v?void 0:v.id)||null,item:{id:i.itemId||null,quantity:i.quantity,variant:{id:i.variantId}},priceListId:s.getPriceListId()||null,salesChannelId:s.getSalesChannelId(),storefrontThemeId:s.getStorefrontThemeId(),metadata:{_fbp:c("_fbp"),_fbc:c("_fbc"),_ga:c("_ga")}}})];case 2:return(r=e.sent()).isSuccess&&r.data?(i.itemId||(a=(null===(h=this.cart)||void 0===h?void 0:h.items.map((function(t){return t.id})))||[],o=r.data.items.map((function(t){return t.id})),(u=o.find((function(t){return!a.includes(t)})))&&(t=r.data.items.find((function(t){return t.id===u})))),[4,this.setCart(r.data)]):[3,4];case 3:e.sent(),e.label=4;case 4:return this.cart&&t&&(l="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(p=i.quantity)>i.quantity?d.removeFromCart(t,p-i.quantity,this.cart):d.addToCart(t,i.quantity-p,l,this.cart)),this.removeCardIfEmpty(),[2,{success:r.isSuccess,response:r}];case 5:return m=e.sent(),console.log(m),[2,{success:!1}];case 6:return[2]}}))}))},this.baseStore=p,r(this)}return Object.defineProperty(p.prototype,"isLoadingCart",{get:function(){return this._isLoadingCart},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"isCartLoadFinished",{get:function(){return this._isCartLoadFinished},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"checkoutId",{get:function(){var t;return null===(t=this.cart)||void 0===t?void 0:t.id},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"checkoutUrl",{get:function(){if(this.checkoutId)return"/checkout?id=".concat(this.checkoutId,"&step=info")},enumerable:!1,configurable:!0}),p.prototype.getAcceptedOffers=function(t){var e=(null==t?void 0:t.filter((function(t){return t.isSelected&&!t.isAccepted})).map((function(t){return{campaignOfferId:t.campaignOfferId,campaignOfferProductId:t.campaignOfferProductId,productId:t.product.id,quantity:t.quantity,variantId:t.product.selectedVariant.id}})))||[];return e.length?e:void 0},p}();!function(t){t.INSUFFICIENT_STOCK="INSUFFICIENT_STOCK",t.INVALID_PRODUCT_OPTION_VALUES="INVALID_PRODUCT_OPTION_VALUES",t.EMPTY_CART="EMPTY_CART"}(l||(l={}));export{p as CART_LS_KEY,l as IkasCartOperationValidationError,m as IkasCartStore};
|
|
1
|
+
import{__awaiter as t,__generator as e,__assign as i}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as r}from"mobx";import n from"./api.js";import"../../models/data/blog/category/index.js";import"../../models/data/blog/content/index.js";import"../../models/data/blog/meta-data/index.js";import"../../models/data/blog/tag/index.js";import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import{IkasProductOptionType as a,IkasCustomerEmailSubscriptionStatus as o}from"@ikas/storefront-models";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import"../../models/data/checkout/index.js";import"../../models/data/checkout-settings/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import"../../models/data/customer/address/region/index.js";import"../../models/data/customer/address/index.js";import"../../models/data/customer/address/ikas-localized-customer-address.js";import"../../models/data/customer/attribute/index.js";import"../../models/data/customer/review/summary/index.js";import"../../models/data/customer/review/index.js";import"../../models/data/customer/index.js";import"../../models/data/customer-form-data-input/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/filter-category/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import"../../models/data/order/address/region/index.js";import"../../models/data/order/address/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/variant/value/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/order-transaction-with-prices/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/payment-gateway/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product/filter/index.js";import"../../models/data/product/campaign-offer/index.js";import"../../models/data/product/option-set/option/index.js";import"../../models/data/product/option-set/index.js";import"../../models/data/product/stock-location/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/variant-type/index.js";import"../../models/data/product/index.js";import"../../models/data/raffle/index.js";import"../../models/data/shipping-zone/state/city/district/region/index.js";import"../../models/data/state/index.js";import"../../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../../models/data/storefront-popup/storefront-popup-page-filter/index.js";import"../../models/data/storefront-popup/index.js";import"../../models/data/theme-json/index.js";import"../../models/data/theme-json/component/index.js";import"../../models/data/theme-json/custom-data/index.js";import"../../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import{IkasStorefrontConfig as s}from"@ikas/storefront-config";import{Analytics as d}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{SaveCartInput as u,createPayWithIkasSessionUrl as c}from"@ikas/storefront-api";import{getCookieValue as l}from"../../utils/helper.js";var p,m="cartId",v=function(){function m(c){var m=this;this.cart=null,this._isLoadingCart=!1,this._isCartLoadFinished=!1,this.addItem=function(r,a,o,u){return void 0===o&&(o=1),t(m,void 0,void 0,(function(){var t,c,m,v,f,h,I,g,C,b,S,y,j,x,O,P,_,T,L,E;return e(this,(function(e){switch(e.label){case 0:t=null!==(y=null==u?void 0:u.isPayWithIkas)&&void 0!==y&&y,e.label=1;case 1:return e.trys.push([1,7,,8]),!t&&a.productOptionSetId&&!a.productOptionSet&&this.baseStore.router?(this.baseStore.router.push(a.productHref),[2,{success:!1,validationError:p.INVALID_PRODUCT_OPTION_VALUES}]):a.hasValidProductOptionValues?r.hasStock||r.sellIfOutOfStock?(c=void 0,t?[3,3]:[4,this.beforeCartOperationCheck()]):[2,{success:!1,validationError:p.INSUFFICIENT_STOCK}]:[2,{success:!1,validationError:p.INVALID_PRODUCT_OPTION_VALUES}];case 2:if(e.sent(),this.cart&&(c=this.findExistingItem(r,a))){if(null===(j=a.productOptionSet)||void 0===j||j.initOptionValues(),!r.bundleSettings)return[2,this.changeItemQuantity(c,c.quantity+1,a.offers,a)];if(!this.getEditLineID())return[2,this.changeItemQuantity(c,c.quantity+1,a.offers,a)]}e.label=3;case 3:return m=this.getOptionValues(a),v=o,(null==(f=null===(x=a.salesChannels)||void 0===x?void 0:x.find((function(t){return t.id===s.getSalesChannelId()})))?void 0:f.minQuantityPerCart)&&o<f.minQuantityPerCart&&(v=f.minQuantityPerCart),(null==f?void 0:f.maxQuantityPerCart)&&o>f.maxQuantityPerCart&&(v=f.maxQuantityPerCart),h=t?null:(null===(O=this.cart)||void 0===O?void 0:O.id)||localStorage.getItem("cartId"),[4,n.addItemToCart({input:i({cartId:h,item:{id:null!==(P=null==c?void 0:c.id)&&void 0!==P?P:null,quantity:null!==(_=null==c?void 0:c.quantity)&&void 0!==_?_:v,variant:{id:r.id,name:a.name,bundleProducts:null===(T=r.bundleSettings)||void 0===T?void 0:T.products.map((function(t){var e,i,r;return{id:t.id,productId:(null===(e=t.product)||void 0===e?void 0:e.id)||"",variantId:(null===(r=null===(i=t.product)||void 0===i?void 0:i.selectedVariant)||void 0===r?void 0:r.id)||"",quantity:t.quantity}}))}},acceptedOffers:this.getAcceptedOffers(a.offers),options:m.length?m:null,priceListId:s.getPriceListId()||null,salesChannelId:s.getSalesChannelId(),storefrontThemeId:s.getStorefrontThemeId(),metadata:{_fbp:l("_fbp"),_fbc:l("_fbc"),_ga:l("_ga")}},a.selectedVariant.subscriptionPlan&&a.selectedVariant.subscriptionPlan.isSelected?{subscriptionPlanId:a.selectedVariant.subscriptionPlan.subscriptionPlanId,subscriptionPlanPeriodId:null===(L=a.selectedVariant.subscriptionPlan.periods.find((function(t){return t.isSelected})))||void 0===L?void 0:L.id}:{})})];case 4:return I=e.sent(),t?[3,6]:I.isSuccess&&I.data?[4,this.setCart(I.data)]:[3,6];case 5:e.sent(),e.label=6;case 6:return(g=t?I.data:this.cart)&&(C="".concat(g.id,"-").concat(g.updatedAt),(b=g.items.find((function(t){return t.variant.id===r.id})))&&d.addToCart(b,o,C,g,a)),null===(E=a.productOptionSet)||void 0===E||E.initOptionValues(),[2,{success:I.isSuccess,response:I}];case 7:return S=e.sent(),console.log(S),[2,{success:!1}];case 8:return[2]}}))}))},this.changeItemQuantity=function(r,a,o,u){return t(m,void 0,void 0,(function(){var t,c,p,m,v,f,h,I,g;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),[4,this.beforeCartOperationCheck()];case 1:return e.sent(),[4,n.addItemToCart({input:i({cartId:(null===(v=this.cart)||void 0===v?void 0:v.id)||null,item:{id:r.id,quantity:a,variant:{id:r.variant.id,name:r.variant.name,bundleProducts:null===(f=r.variant.bundleProducts)||void 0===f?void 0:f.map((function(t){return{id:t.id,productId:t.variant.productId||"",variantId:t.variant.id||"",quantity:t.quantity}}))}},acceptedOffers:this.getAcceptedOffers(o),options:this.createCartLineOptions(r),priceListId:s.getPriceListId()||null,salesChannelId:s.getSalesChannelId(),storefrontThemeId:s.getStorefrontThemeId(),metadata:{_fbp:l("_fbp"),_fbc:l("_fbc"),_ga:l("_ga")}},(null===(h=null==u?void 0:u.selectedVariant)||void 0===h?void 0:h.subscriptionPlan)&&(null===(I=null==u?void 0:u.selectedVariant)||void 0===I?void 0:I.subscriptionPlan.isSelected)?{subscriptionPlanId:null==u?void 0:u.selectedVariant.subscriptionPlan.subscriptionPlanId,subscriptionPlanPeriodId:null===(g=null==u?void 0:u.selectedVariant.subscriptionPlan.periods.find((function(t){return t.isSelected})))||void 0===g?void 0:g.id}:{})})];case 2:return(t=e.sent()).isSuccess&&t.data?[4,this.setCart(t.data)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.cart&&(c="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(p=r.quantity)>a?d.removeFromCart(r,p-a,this.cart):d.addToCart(r,a-p,c,this.cart,u)),this.removeCardIfEmpty(),[2,{success:t.isSuccess,response:t}];case 5:return m=e.sent(),console.log(m),[2,{success:!1}];case 6:return[2]}}))}))},this.createCart=function(i){return t(m,void 0,void 0,(function(){var t,r=this;return e(this,(function(e){switch(e.label){case 0:return[4,n.createCart({input:{items:i.variantLines.map((function(t){return{variant:{id:t.variantId},quantity:t.quantity}})),couponCode:i.couponCode,salesChannelId:s.getSalesChannelId(),storefrontThemeId:s.getStorefrontThemeId()}})];case 1:return(t=e.sent()).isSuccess&&t.data?[4,this.setCart(t.data)]:[3,3];case 2:e.sent(),e.label=3;case 3:return i.variantLines.forEach((function(t){if(r.cart){var e="".concat(r.cart.id,"-").concat(r.cart.updatedAt),i=r.cart.items.find((function(e){return e.variant.id===t.variantId}));i&&d.addToCart(i,t.quantity,e,r.cart)}})),[2,{success:t.isSuccess,response:t}]}}))}))},this.removeItem=function(i){return t(m,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.changeItemQuantity(i,0)];case 1:return[2,t.sent()]}}))}))},this.removeCart=function(){localStorage.removeItem("cartId"),m.cart=void 0},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){m.isCartLoadFinished&&(clearInterval(e),t(null))}),100)}))},this.getEditLineID=function(){if("undefined"!=typeof window)return new URLSearchParams(window.location.search).get("editLineID")||""},this.findExistingItem=function(t,e){var i,r,n,a,o,s;if(!e.productOptionSetId&&!t.bundleSettings)return null===(i=m.cart)||void 0===i?void 0:i.orderLineItems.find((function(e){return e.variant.id===t.id}));if(t.bundleSettings){var d=m.getEditLineID();if(d)if(S=null===(r=m.cart)||void 0===r?void 0:r.orderLineItems.find((function(t){return t.id===d})))return S}var u=(null===(n=m.cart)||void 0===n?void 0:n.orderLineItems.filter((function(e){return e.variant.id===t.id})))||[];if(e.productOptionSetId)for(var c=m.getOptionValues(e),l=u.filter((function(t){var e;return(null===(e=t.options)||void 0===e?void 0:e.length)===c.length}))||[],p=0,v=l;p<v.length;p++){if((S=v[p]).options){for(var f=!0,h=function(t){var i=t.values.map((function(t){return t.value})),r=null===(s=null===(o=null===(a=e.productOptionSet)||void 0===a?void 0:a.options)||void 0===o?void 0:o.find((function(e){return e.id===t.productOptionId})))||void 0===s?void 0:s.values;if(!(f=f&&i.length===(null==r?void 0:r.length)&&i.every((function(t){return null==r?void 0:r.includes(t)}))))return"break"},I=0,g=S.options;I<g.length;I++){if("break"===h(g[I]))break}if(f){if(!t.bundleSettings)return S;if(m.isSameBundleItem(t,S))return S}}}else if(t.bundleSettings)for(var C=0,b=u;C<b.length;C++){var S=b[C];if(m.isSameBundleItem(t,S))return S}},this.isSameBundleItem=function(t,e){var i,r=null===(i=t.bundleSettings)||void 0===i?void 0:i.products,n=e.variant.bundleProducts;return!!r&&((null==r?void 0:r.length)===(null==n?void 0:n.length)&&(null==r?void 0:r.every((function(t){return!!(null==n?void 0:n.find((function(e){var i;return e.id===t.id&&e.quantity===t.quantity&&e.variant.id===(null===(i=t.product)||void 0===i?void 0:i.selectedVariant.id)})))}))))},this.saveCouponCode=function(i){return t(m,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.cart?[4,n.saveCartCouponCode({cartId:this.cart.id,couponCode:i})]:[2,{success:!1,validationError:p.EMPTY_CART}];case 1:return(t=e.sent()).isSuccess&&t.data&&(this.cart=t.data),[2,{success:t.isSuccess,response:t}]}}))}))},this.removeCouponCode=function(){return t(m,void 0,void 0,(function(){return e(this,(function(t){return[2,this.saveCouponCode(null)]}))}))},this.removeGiftCardLine=function(i){return t(m,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.cart?[4,n.removeGiftCardFromCart({cartId:this.cart.id,giftCardId:i})]:[2,{success:!1,validationError:p.EMPTY_CART}];case 1:return(t=e.sent()).isSuccess&&t.data&&(this.cart=t.data),[2,{success:t.isSuccess,response:t}]}}))}))},this.removeLoyaltyPointsFromCart=function(i){return t(m,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.cart?[4,n.removeLoyaltyPointsFromCart({cartId:this.cart.id,loyaltySpendingMethodId:i})]:[2,{success:!1,validationError:p.EMPTY_CART}];case 1:return(t=e.sent()).isSuccess&&t.data&&(this.cart=t.data),[2,{success:t.isSuccess,response:t}]}}))}))},this.saveCart=function(i){return t(m,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return(t=new u(i)).customer&&this.baseStore.customerStore.customer&&(t.customer.notificationsAccepted=this.baseStore.customerStore.customer.subscriptionStatus===o.SUBSCRIBED),[4,n.saveCart({input:t})];case 1:return[2,{success:(r=e.sent()).isSuccess,response:r}]}}))}))},this.removeCardIfEmpty=function(){var t;0===(null===(t=m.cart)||void 0===t?void 0:t.itemCount)&&m.removeCart()},this.getCart=function(){return t(m,void 0,void 0,(function(){var t,i,r,a,o,s;return e(this,(function(e){switch(e.label){case 0:if(!("undefined"!=typeof localStorage))return[2];e.label=1;case 1:return e.trys.push([1,6,7,8]),this._isLoadingCart=!0,t=null===(o=this.baseStore.customerStore.customer)||void 0===o?void 0:o.id,(i=(null===(s=this.cart)||void 0===s?void 0:s.id)||localStorage.getItem("cartId"))||t?[4,n.getCartById({id:i})]:[2];case 2:return(r=e.sent()).isSuccess&&r.data?[4,this.setCart(r.data)]:[3,4];case 3:return e.sent(),[3,5];case 4:this.removeCart(),e.label=5;case 5:return[3,8];case 6:return a=e.sent(),console.log(a),[3,8];case 7:return this._isLoadingCart=!1,this._isCartLoadFinished=!0,[7];case 8:return[2]}}))}))},this.setCart=function(i){return t(m,void 0,void 0,(function(){return e(this,(function(t){return localStorage.setItem("cartId",i.id),this.cart=i,[2]}))}))},this.beforeCartOperationCheck=function(){return t(m,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return t=localStorage.getItem("cartId"),!this.cart||t?[3,1]:(this.removeCart(),[3,3]);case 1:return this.cart||!t?[3,3]:[4,this.getCart()];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},this.createCartLineOptions=function(t){if(t&&t.options){for(var e=[],i=0,r=t.options;i<r.length;i++){var n=r[i],a={productOptionId:n.productOptionId,productOptionsSetId:n.productOptionsSetId,values:n.values.map((function(t){return t.value}))};e.push(a)}return e}return null},this.getOptionValues=function(t){var e,i=[];return null===(e=t.productOptionSet)||void 0===e||e.options.forEach((function(t){var e=t.values;t.type===a.DATE_PICKER&&(e=t.values.map((function(t){var e=new Date(t);return isNaN(e.getTime())?t:e.toISOString().split("T")[0]}))),t.values.length&&i.push({productOptionId:t.id,productOptionsSetId:t.productOptionSetId,values:e})})),i},this._windowAddToCart=function(i){return t(m,void 0,void 0,(function(){var t,r,a,o,u,c,p,m,v,f,h;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),[4,this.beforeCartOperationCheck()];case 1:return e.sent(),t=i.itemId?null===(v=this.cart)||void 0===v?void 0:v.items.find((function(t){return t.id===i.itemId})):null,[4,n.addItemToCart({input:{cartId:(null===(f=this.cart)||void 0===f?void 0:f.id)||null,item:{id:i.itemId||null,quantity:i.quantity,variant:{id:i.variantId}},priceListId:s.getPriceListId()||null,salesChannelId:s.getSalesChannelId(),storefrontThemeId:s.getStorefrontThemeId(),metadata:{_fbp:l("_fbp"),_fbc:l("_fbc"),_ga:l("_ga")}}})];case 2:return(r=e.sent()).isSuccess&&r.data?(i.itemId||(a=(null===(h=this.cart)||void 0===h?void 0:h.items.map((function(t){return t.id})))||[],o=r.data.items.map((function(t){return t.id})),(u=o.find((function(t){return!a.includes(t)})))&&(t=r.data.items.find((function(t){return t.id===u})))),[4,this.setCart(r.data)]):[3,4];case 3:e.sent(),e.label=4;case 4:return this.cart&&t&&(c="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(p=i.quantity)>i.quantity?d.removeFromCart(t,p-i.quantity,this.cart):d.addToCart(t,i.quantity-p,c,this.cart)),this.removeCardIfEmpty(),[2,{success:r.isSuccess,response:r}];case 5:return m=e.sent(),console.log(m),[2,{success:!1}];case 6:return[2]}}))}))},this.baseStore=c,r(this)}return Object.defineProperty(m.prototype,"isLoadingCart",{get:function(){return this._isLoadingCart},enumerable:!1,configurable:!0}),Object.defineProperty(m.prototype,"isCartLoadFinished",{get:function(){return this._isCartLoadFinished},enumerable:!1,configurable:!0}),Object.defineProperty(m.prototype,"checkoutId",{get:function(){var t;return null===(t=this.cart)||void 0===t?void 0:t.id},enumerable:!1,configurable:!0}),Object.defineProperty(m.prototype,"checkoutUrl",{get:function(){if(this.checkoutId)return"/checkout?id=".concat(this.checkoutId,"&step=info")},enumerable:!1,configurable:!0}),m.prototype.getAcceptedOffers=function(t){var e=(null==t?void 0:t.filter((function(t){return t.isSelected&&!t.isAccepted})).map((function(t){return{campaignOfferId:t.campaignOfferId,campaignOfferProductId:t.campaignOfferProductId,productId:t.product.id,quantity:t.quantity,variantId:t.product.selectedVariant.id}})))||[];return e.length?e:void 0},m.prototype.createPayWithIkasSession=function(i,r){var n,a,o,d,u,l,p,m;return void 0===r&&(r=1),t(this,void 0,void 0,(function(){var t,v,f,h,I,g,C;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),t=s.getSalesChannelId(),v=s.getStorefrontThemeId(),t&&v?(f=i.selectedVariant)?[4,this.addItem(f,i,r,{isPayWithIkas:!0})]:[2,{success:!1,error:"No variant selected"}]:[2,{success:!1,error:"Missing storefront configuration"}];case 1:return(h=e.sent()).success&&(null===(a=null===(n=h.response)||void 0===n?void 0:n.data)||void 0===a?void 0:a.id)?(I=h.response.data.id,[4,c({cartId:I})]):[2,{success:!1,error:(null===(u=null===(d=null===(o=h.response)||void 0===o?void 0:o.graphQLErrors)||void 0===d?void 0:d[0])||void 0===u?void 0:u.message)||"Failed to create cart"}];case 2:return!(g=e.sent()).data||(null===(l=g.graphQLErrors)||void 0===l?void 0:l.length)?[2,{success:!1,error:(null===(m=null===(p=g.graphQLErrors)||void 0===p?void 0:p[0])||void 0===m?void 0:m.message)||"Failed to create Pay with ikas session"}]:[2,{success:!0,payUrl:g.data.payUrl,expiresAt:g.data.expiresAt}];case 3:return[2,{success:!1,error:(C=e.sent())instanceof Error?C.message:"Unknown error occurred"}];case 4:return[2]}}))}))},m}();!function(t){t.INSUFFICIENT_STOCK="INSUFFICIENT_STOCK",t.INVALID_PRODUCT_OPTION_VALUES="INVALID_PRODUCT_OPTION_VALUES",t.EMPTY_CART="EMPTY_CART"}(p||(p={}));export{m as CART_LS_KEY,p as IkasCartOperationValidationError,v as IkasCartStore};
|
package/build/store/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikas/storefront",
|
|
3
|
-
"version": "6.1.0-beta.
|
|
3
|
+
"version": "6.1.0-beta.223",
|
|
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": "^6.1.0-beta.
|
|
27
|
-
"@ikas/storefront-config": "^6.1.0-beta.
|
|
28
|
-
"@ikas/storefront-model-functions": "^6.1.0-beta.
|
|
29
|
-
"@ikas/storefront-models": "^6.1.0-beta.
|
|
30
|
-
"@ikas/storefront-providers": "^6.1.0-beta.
|
|
26
|
+
"@ikas/storefront-api": "^6.1.0-beta.223",
|
|
27
|
+
"@ikas/storefront-config": "^6.1.0-beta.223",
|
|
28
|
+
"@ikas/storefront-model-functions": "^6.1.0-beta.223",
|
|
29
|
+
"@ikas/storefront-models": "^6.1.0-beta.223",
|
|
30
|
+
"@ikas/storefront-providers": "^6.1.0-beta.223",
|
|
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": "^6.1.0-beta.
|
|
66
|
-
"@ikas/storefront-config": "^6.1.0-beta.
|
|
67
|
-
"@ikas/storefront-model-functions": "^6.1.0-beta.
|
|
68
|
-
"@ikas/storefront-models": "^6.1.0-beta.
|
|
69
|
-
"@ikas/storefront-providers": "^6.1.0-beta.
|
|
65
|
+
"@ikas/storefront-api": "^6.1.0-beta.223",
|
|
66
|
+
"@ikas/storefront-config": "^6.1.0-beta.223",
|
|
67
|
+
"@ikas/storefront-model-functions": "^6.1.0-beta.223",
|
|
68
|
+
"@ikas/storefront-models": "^6.1.0-beta.223",
|
|
69
|
+
"@ikas/storefront-providers": "^6.1.0-beta.223",
|
|
70
70
|
"mobx": "^6.1.3",
|
|
71
71
|
"mobx-react-lite": "^3.1.5",
|
|
72
72
|
"next": "12.2.0",
|