@ikas/storefront 2.0.68 → 2.0.69
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/_virtual/index.js_commonjs-proxy2.js +1 -1
- package/build/_virtual/index.js_commonjs-proxy3.js +1 -1
- package/build/_virtual/index.js_commonjs-proxy4.js +1 -1
- package/build/api/cart/index.d.ts +3 -1
- package/build/api/cart/index.js +1 -1
- package/build/ikas.js +1 -1
- package/build/models/ui/product-list/index.js +1 -1
- package/build/store/cart.d.ts +24 -2
- package/build/store/cart.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as t,__generator as e}from'../../../ext/tslib/tslib.es6.js';import{makeAutoObservable as i}from"mobx";import"../../theme/theme.js";import{IkasThemePageType as r}from"../../theme/page/index.js";import"../../theme/component/prop/index.js";import"../../theme/page/component/prop-value/link.js";import"../brand-list/index.js";import"../blog-list/index.js";import"../blog-category-list/index.js";import"../category-list/index.js";import{IkasProductDetail as s}from"../product-detail/index.js";import"../product-attribute-detail/index.js";import"../product-attribute-list/index.js";import"../customer-review-list/index.js";import"../customer-review-summary-list/index.js";import"../validator/index.js";import"../validator/rules/index.js";import"../validator/form/login.js";import"../validator/form/address.js";import"../validator/form/register.js";import"../validator/form/contact-form.js";import"../validator/form/forgot-password.js";import"../validator/form/recover-password.js";import"../validator/form/account-info.js";import"../validator/form/raffle-form.js";import"../validator/form/customer-review.js";import"../raffle-list/index.js";import"../../theme/settings/index.js";import"../../theme/custom-data/index.js";import"../../../api/blog/index.js";import"../../../api/brand/index.js";import"../../../api/cart/index.js";import"../../../api/category/index.js";import"../../../api/checkout/index.js";import"../../../api/city/index.js";import"../../../api/country/index.js";import"../../../api/customer/index.js";import"../../../api/customer-review/index.js";import"../../../api/customer-review-summary/index.js";import"../../../api/district/index.js";import"../../../api/html-meta-data/index.js";import"../../../api/merchant/index.js";import{IkasProductSearchAPI as n}from"../../../api/product-search/index.js";import"../../data/blog/index.js";import"../../data/brand/index.js";import{ModelOrder as a,IkasFilterCategory as o}from"../../data/category/index.js";import"../../data/checkout/index.js";import"../../data/customer/address/index.js";import"../../data/customer/index.js";import"../../data/customer-review/index.js";import"../../data/html-meta-data/index.js";import"../../data/image/index.js";import"../../data/installment-info/index.js";import"../../data/merchant-settings/index.js";import"../../data/order/index.js";import"../../data/order/line-item/index.js";import"../../../api/product-option-file/index.js";import"../../data/product/index.js";import"../../data/variant-type/index.js";import"../../data/product/variant/index.js";import"../../data/product/variant/price/index.js";import"../../data/product-attribute/index.js";import"../../data/product/attribute-value/index.js";import{IkasProductFilter as u,IkasProductFilterValue as c}from"../../data/product-filter/index.js";import"../../data/variant-type/variant-value/index.js";import"../../data/order-transaction/index.js";import"../../data/product-option-set/index.js";import"../../data/raffle/index.js";import"../../data/product-campaing/campaign/index.js";import"../../data/customer-attribute/index.js";import"../../data/customer-attribute/customer-attribute-sales-channel/index.js";import"../../../api/apollo.js";import"../../../api/favorite-product/index.js";import"../../../api/contact-form/index.js";import"../../../api/state/index.js";import"../../../api/product-option-set/index.js";import"../../../api/raffle/index.js";import"../../../api/back-in-stock-reminder/index.js";import"../../../api/product-campaign/index.js";import l from'../../../ext/query-string/index.js';import d from'../../../ext/lodash/debounce.js';import{Analytics as p}from"../../../analytics/analytics.js";import"../../../analytics/head/index.js";import{IkasStorefrontConfig as h}from"../../../storefront/index.js";import{SortByDirectionEnum as f,SortByTypeEnum as m}from"../../../__generated__/global-types.js";var g,_,y,v=function(){function y(n,a){var c=this;if(this.filters=null,this._filterCategories=null,this._infiniteScrollPage=null,this._initialized=!1,this._minPage=null,this._filterBrandId=null,this._filterCategoryId=null,this._relatedProductData=null,this.pageSpecificData=null,this._recommendFor=null,this._isLoading=!1,this._fetchRequestTime=0,this.router=null,this.applyFilters=function(){return t(c,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,this.getInitial()];case 1:return t=e.sent(),[r.CATEGORY,r.BRAND,r.SEARCH].includes(this._pageType)?(t&&this.isBrowser()&&!this.isSearch&&!h.isEditor&&(null===(i=this.router)||void 0===i||i.replace("".concat(location.pathname).concat(this.filterQueryParams?"?"+this.filterQueryParams:""),void 0,{shallow:!0})),[2]):[2]}}))}))},this.getInitial=function(i,r){return t(c,void 0,void 0,(function(){var t,n,a,o,u,c,l,d,p;return e(this,(function(e){switch(e.label){case 0:this._isLoading=!0,t=Date.now(),this._fetchRequestTime=t,e.label=1;case 1:return e.trys.push([1,12,13,14]),n=r?this._page:1,a=this._limit,!this.isFilterable||this.filters?[3,3]:[4,this.getFilters()];case 2:e.sent(),e.label=3;case 3:return this.applyQueryParamFilters(i),this.isSearch&&!this.hasAppliedfilter?(this.data=[],this._page=1,this._minPage=1,this._count=0,this._initialized=!0,[2,!0]):(o=void 0,this.isStatic?(n=void 0,a=200,[3,10]):[3,4]);case 4:return this.isDiscounted?(n=1,a=10,[3,10]):[3,5];case 5:return this.isRecommended?(n=1,a=10,[3,10]):[3,6];case 6:return this.isLastViewed?this.isBrowser()?[4,this.waitForCustomerStoreInit()]:[3,9]:[3,10];case 7:return e.sent(),[4,h.store.customerStore.getLastViewedProducts()];case 8:return(u=e.sent())&&u.length&&(o=u.map((function(t){return t.productId}))),[3,10];case 9:return[2];case 10:return[4,this.searchProducts(n||1,a||10,o)];case 11:return(c=e.sent())&&this._fetchRequestTime===t?(l=[],this.isStatic||this.isLastViewed?(d=this.isStatic?this._productListPropValue.productIds:h.store.customerStore._lastViewedProducts,l=(null==d?void 0:d.map((function(t){var e=c.data.find((function(e){return e.id===t.productId})),i=null==e?void 0:e.variants.find((function(e){return e.id===t.variantId}));if((null==i?void 0:i.isActive)||(i=null==e?void 0:e.variants.find((function(t){return t.isActive}))),e&&i)return new s(e,i.variantValues)})).filter((function(t){return!!t})))||[]):l=c.data.map((function(t){var e=t.variants.find((function(t){return t.isActive}));return new s(t,(e||t.variants[0]).variantValues)})),this.applyFacets(c.facets),this.data=l,this._count=c.count,this._initialized=!0,this._page=n||1,this._minPage=this.page,r||(this._infiniteScrollPage=null),this.handleListingEvent(),[2,!0]):[2];case 12:return p=e.sent(),console.log(p),[3,14];case 13:return t===this._fetchRequestTime&&(this._isLoading=!1),[7];case 14:return[2]}}))}))},this.getPrev=function(){return t(c,void 0,void 0,(function(){var t,i,r,n;return e(this,(function(e){switch(e.label){case 0:if(this.isStatic||this.isDiscounted||this.isRecommended||this.isLastViewed||this._isLoading||!this.hasPrev)return[2];this._isLoading=!0,e.label=1;case 1:return e.trys.push([1,3,4,5]),t=this._minPage-1,[4,this.searchProducts(t,this.limit)];case 2:return(i=e.sent())?(r=i.data.map((function(t){var e=t.variants.find((function(t){return t.isActive}));return new s(t,(e||t.variants[0]).variantValues)})),this.data=r.concat(this.data),this._count=i.count,this._minPage=t,[3,5]):[2];case 3:return n=e.sent(),console.log(n),[3,5];case 4:return this._isLoading=!1,[7];case 5:return[2]}}))}))},this.getNext=function(){return t(c,void 0,void 0,(function(){var t,i,r;return e(this,(function(e){switch(e.label){case 0:if(this.isStatic||this.isDiscounted||this.isRecommended||this.isLastViewed||this._isLoading||!this.hasNext)return[2];this._isLoading=!0,e.label=1;case 1:return e.trys.push([1,3,4,5]),[4,this.searchProducts(this.page+1,this.limit)];case 2:return(t=e.sent())?(i=t.data.map((function(t){var e=t.variants.find((function(t){return t.isActive}));return new s(t,(e||t.variants[0]).variantValues)})),this.data=this.data.concat(i),this._count=t.count,this._page=this.page+1,[3,5]):[2];case 3:return r=e.sent(),console.log(r),[3,5];case 4:return this._isLoading=!1,[7];case 5:return[2]}}))}))},this.getPage=function(i){return t(c,void 0,void 0,(function(){var t,r,n;return e(this,(function(e){switch(e.label){case 0:if(this._isLoading||this.isStatic||this.isDiscounted||this.isRecommended||this.isLastViewed)return[2];this._isLoading=!0,e.label=1;case 1:return e.trys.push([1,3,4,5]),[4,this.searchProducts(i,this.limit)];case 2:return(t=e.sent())?(r=t.data.map((function(t){var e=t.variants.find((function(t){return t.isActive}));return new s(t,(e||t.variants[0]).variantValues)})),this.data=r,this._count=t.count,this._page=i,this._minPage=i,[3,5]):[2];case 3:return n=e.sent(),console.log(n),[3,5];case 4:return this._isLoading=!1,[7];case 5:return[2]}}))}))},this.setVisibleInfiniteScrollPage=function(t){var e;c._infiniteScrollPage!==t&&(c._infiniteScrollPage=t,h.isEditor||null===(e=c.router)||void 0===e||e.replace("".concat(location.pathname).concat(c.filterQueryParams?"?"+c.filterQueryParams:""),void 0,{shallow:!0}))},this.searchDebouncer=d((function(){c.applyFilters()}),100),this.searchAnalyticsDebouncer=d((function(){p.search(c._searchKeyword)}),1e3),this.data=n.data?n.data.map((function(t){return new s(t.product,t.selectedVariantValues)})):[],this._type=n.type||n.productListPropValue.productListType||g.ALL,this._pageType=n.pageType,this._sort=n.sort||n.productListPropValue.initialSort||_.LAST_ADDED,"A_Z"!==this.initialSort&&"Z_A"!==this.initialSort||(this._sort=_.LAST_ADDED),this._limit=n.limit||n.productListPropValue.initialLimit||20,this._page=n.page||1,this._minPage=n.minPage||null,this._count=n.count||0,this._searchKeyword=n.searchKeyword||"",this._productListPropValue=n.productListPropValue,this._filterBrandId=n.filterBrandId||null,this._filterCategoryId=n.filterCategoryId||null,this._relatedProductData=n.relatedProductData||null,this._recommendFor=n.recommendFor,this.filters=n.filters?n.filters.map((function(t){return new u(t,c)})):null,this._filterCategories=n.filterCategories?n.filterCategories.map((function(t){return new o(t)})):null,this.pageSpecificData=n.pageSpecificData||null,this.router=a,i(this),this.setPageSpecificSort(),this.isBrowser())if(this.restoreInfiniteScrollPage(),location.search&&(this.isFilterable||this._type===g.SEARCH)){var l=this.getQueryParams();this.getInitial(l,this._page>1)}else this._page>1?this.getInitial(void 0,!0):this.isLastViewed?this.getInitial():this.handleListingEvent()}return Object.defineProperty(y.prototype,"sort",{get:function(){return this._sort},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"limit",{get:function(){return this._limit},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"pageType",{get:function(){return this._pageType},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"page",{get:function(){return this._page},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"minPage",{get:function(){return this._minPage||1},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"count",{get:function(){return this._count},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"pageCount",{get:function(){return Math.ceil(this._count/this._limit)},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"searchKeyword",{get:function(){return this._searchKeyword},set:function(t){t!==this._searchKeyword&&(this._searchKeyword=t,this.searchDebouncer(),this.searchAnalyticsDebouncer())},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isInitialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isFilterable",{get:function(){return this._type===g.ALL||this._type===g.CATEGORY},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isFiltered",{get:function(){var t,e;return(null===(t=this.filters)||void 0===t?void 0:t.some((function(t){return!!t.valueList.length})))||!!this._searchKeyword||this._pageType!==r.CATEGORY&&(!!this._filterCategoryId||(null===(e=this._filterCategories)||void 0===e?void 0:e.some((function(t){return t.isSelected}))))},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isStatic",{get:function(){return this._type===g.STATIC},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isDiscounted",{get:function(){return this._type===g.DISCOUNTED},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isRecommended",{get:function(){return this._type===g.RECOMMENDED},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isLastViewed",{get:function(){return this._type===g.LAST_VIEWED},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isRelatedProducts",{get:function(){return this._type===g.RELATED_PRODUCTS},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isSearch",{get:function(){return this._type===g.SEARCH},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"hasPrev",{get:function(){return!(this.isStatic||this.isDiscounted||this.isRecommended||!this._minPage)&&this._minPage>1},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"hasNext",{get:function(){return!(this.isStatic||this.isDiscounted||this.isRecommended)&&this.page*this.limit<this.count},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isLoading",{get:function(){return this._isLoading},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"filterQueryParams",{get:function(){var t,e,i,s,n=this,a={},o=this.getQueryParams();if(o&&o.forEach((function(t,e){a[e]=t})),null===(t=this.filters)||void 0===t||t.forEach((function(t){t.keyList.length&&(a[t.key]=t.keyList)})),this._searchKeyword&&(a.s=this._searchKeyword),this._infiniteScrollPage&&(a.page=this._infiniteScrollPage),this._pageType!==r.CATEGORY){var u=null===(e=this.filterCategories)||void 0===e?void 0:e.filter((function(t){return t.isSelected}));if(!!(null==u?void 0:u.length))a.c=null==u?void 0:u.map((function(t){return t.slug}));else if(this._filterCategoryId){var c=null===(s=null===(i=this.filterCategories)||void 0===i?void 0:i.find((function(t){return t.id===n._filterCategoryId})))||void 0===s?void 0:s.slug;c&&(a.c=c)}}return l.stringify(a,{arrayFormat:"comma"})},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"filterCategories",{get:function(){var t;return null===(t=this._filterCategories)||void 0===t?void 0:t.filter((function(t){return 0!==t.resultCount}))},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"hasAppliedfilter",{get:function(){var t;return!!this._searchKeyword||(null===(t=this.filters)||void 0===t?void 0:t.some((function(t){return!!t.valueList.length})))},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isFeaturedSortEnabled",{get:function(){var t;return(null===(t=this.pageSpecificData)||void 0===t?void 0:t.orderType)===a.MANUALLY&&[g.ALL,g.CATEGORY].includes(this._type)},enumerable:!1,configurable:!0}),y.prototype.setPageSpecificSort=function(){var t;if((null===(t=this.pageSpecificData)||void 0===t?void 0:t.orderType)&&[g.ALL,g.CATEGORY].includes(this._type))switch(this.pageSpecificData.orderType){case a.HIGHEST_DISCOUNT_RATIO:this._sort=_.DECRASING_DISCOUNT;break;case a.LOWEST_DISCOUNT_RATIO:this._sort=_.INCREASING_DISCOUNT;break;case a.HIGHEST_PRICE:this._sort=_.DECREASING_PRICE;break;case a.LOWEST_PRICE:this._sort=_.INCREASING_PRICE;break;case a.NEWEST:this._sort=_.LAST_ADDED;break;case a.OLDEST:this._sort=_.FIRST_ADDED;break;case a.MANUALLY:this._sort=_.FEATURED}},y.prototype.getSortParams=function(){var t=f.DESC,e=m.CREATED_AT;switch(this._sort){case _.INCREASING_PRICE:t=f.ASC,e=m.PRICE;break;case _.DECREASING_PRICE:t=f.DESC,e=m.PRICE;break;case _.FIRST_ADDED:t=f.ASC,e=m.CREATED_AT;break;case _.LAST_ADDED:t=f.DESC,e=m.CREATED_AT;break;case _.INCREASING_DISCOUNT:t=f.ASC,e=m.DISCOUNT_RATIO;break;case _.DECRASING_DISCOUNT:t=f.DESC,e=m.DISCOUNT_RATIO;break;case _.FEATURED:if(this.isSearch)return;t=f.ASC,e=m.MANUAL_SORT}return{direction:t,type:e}},y.prototype.searchProducts=function(i,s,a){var o,u,l;return t(this,void 0,void 0,(function(){var t,d,p,f;return e(this,(function(e){switch(e.label){case 0:return t=[],d=[],null===(o=this.filters)||void 0===o||o.forEach((function(e){e.valueList.length&&t.push(new c({id:e.id,type:e.type,displayType:e.displayType,valueList:e.valueList})),e.isFacetFilter&&d.push({id:e.id,type:e.type,displayType:e.displayType})})),p=null===(u=this._filterCategories)||void 0===u?void 0:u.filter((function(t){return t.isSelected})).map((function(t){return t.id})),f=this.getSortParams(),this.isRelatedProducts&&this._relatedProductData?[4,n.getRelatedProducts({priceListId:h.priceListId,salesChannelId:h.salesChannelId,productId:this._relatedProductData.productId,brandIds:this._relatedProductData.brandIds,categoryIds:this._relatedProductData.categoryIds})]:[3,2];case 1:case 3:return[2,e.sent()];case 2:return[4,n.searchProducts({page:i,perPage:s,productIdList:this.isStatic?null===(l=this._productListPropValue.productIds)||void 0===l?void 0:l.map((function(t){return t.productId})):a,filterList:t,facetList:d,brandId:this._pageType===r.BRAND&&this._type!==g.SEARCH?this._filterBrandId:void 0,categoryIdList:p&&p.length?p:this._filterCategoryId?[this._filterCategoryId]:void 0,priceListId:h.priceListId,salesChannelId:h.salesChannelId,query:this._searchKeyword,order:this._type===g.SEARCH?null:f?[f]:null},!0)]}}))}))},y.prototype.getFilters=function(){var i;return t(this,void 0,void 0,(function(){var t,s,a=this;return e(this,(function(e){switch(e.label){case 0:return[4,n.getProductFilterData(this._filterCategoryId?this._filterCategoryId:void 0)];case 1:return t=e.sent(),this.filters=null==t?void 0:t.filters.map((function(t){return new u(t,a)})),this._filterCategories=null==t?void 0:t.categories,this.pageType!==r.CATEGORY&&this._filterCategoryId&&(s=null===(i=this._filterCategories)||void 0===i?void 0:i.find((function(t){return t.id===a._filterCategoryId})))&&(s._isSelected=!0),this.filters&&this.filters.sort((function(t,e){return t.order>e.order?1:-1})),[2]}}))}))},y.prototype.applyQueryParamFilters=function(t){var e,i=this;try{null==t||t.forEach((function(t,e){var r,s=null===(r=i.filters)||void 0===r?void 0:r.find((function(t){return t.key===e}));s&&s.applyQueryParam(t)}));var s=null==t?void 0:t.get("s");if(s&&(this._searchKeyword=s),this._pageType!==r.CATEGORY){var n=null==t?void 0:t.get("c"),a=null==n?void 0:n.split(",");a&&a.length&&(null===(e=this.filterCategories)||void 0===e||e.forEach((function(t){t._isSelected=a.some((function(e){return e===t.slug}))})))}}catch(t){console.log(t)}},y.prototype.applyFacets=function(t){var e,i;null===(e=this.filters)||void 0===e||e.forEach((function(e){var i,r,s,n=null==t?void 0:t.find((function(t){return t.id===e.id}));n?null===(i=e.values)||void 0===i||i.forEach((function(t){var i=n.values.find((function(e){return e.id===t.id}));i?t.resultCount=i.count:e.isCustomValueFilter?t.resultCount=null:t.resultCount=0})):e.isCustomValueFilter?null===(r=e.values)||void 0===r||r.forEach((function(t){return t.resultCount=null})):null===(s=e.values)||void 0===s||s.forEach((function(t){return t.resultCount=0}))}));var r=null==t?void 0:t.find((function(t){return"category"===t.id}));r&&(null===(i=this._filterCategories)||void 0===i||i.forEach((function(t){var e=r.values.find((function(e){return e.id===t.id}));t.resultCount=e?e.count:0})))},y.prototype.clearFilters=function(){var t,e;null===(t=this.filters)||void 0===t||t.forEach((function(t){return t.clear()})),this._searchKeyword="",this._pageType!==r.CATEGORY&&(this._filterCategoryId=void 0),null===(e=this._filterCategories)||void 0===e||e.forEach((function(t){return t._isSelected=!1})),this.applyFilters()},y.prototype.setSortType=function(i){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this._sort=i,[4,this.getInitial()];case 1:return t.sent(),[2]}}))}))},y.prototype.onFilterCategoryClick=function(i,r){var s,n;return void 0===r&&(r=!1),t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return r?(null===(s=this._filterCategories)||void 0===s||s.forEach((function(t){t.id===i.id&&(t._isSelected=!t.isSelected)})),[4,this.applyFilters()]):[3,2];case 1:return t.sent(),[3,3];case 2:h.isEditor||null===(n=this.router)||void 0===n||n.push(i.href+(this.filterQueryParams?"?"+this.filterQueryParams:"")),t.label=3;case 3:return[2]}}))}))},y.prototype.toJSON=function(){return{data:this.data,type:this._type,pageType:this._pageType,sort:this._sort,limit:this._limit,page:this._page,count:this._count,searchKeyword:this._searchKeyword,initialized:this._initialized,minPage:this._minPage,filterBrandId:this._filterBrandId,filterCategoryId:this._filterCategoryId,filterCategories:this._filterCategories,filters:this.filters,recommendFor:this._recommendFor,productListPropValue:this._productListPropValue,pageSpecificData:this.pageSpecificData}},y.prototype.restoreInfiniteScrollPage=function(){var t=this.getQueryParams(),e=null==t?void 0:t.get("page");if(e){var i=parseInt(e);isNaN(i)||(this._page=i,this._infiniteScrollPage=i)}},y.prototype.getQueryParams=function(){if(this.isBrowser())return new URLSearchParams(location.search)},y.prototype.isBrowser=function(){return"undefined"!=typeof window},y.prototype.waitForCustomerStoreInit=function(){return new Promise((function(t){var e=setInterval((function(){h.store.customerStore.initialized&&(clearInterval(e),t(null))}),1e3)}))},y.prototype.handleListingEvent=function(){this.searchKeyword&&this.data.length?p.viewSearchResults(this._searchKeyword,this.data):this.data.length&&this._type===g.ALL&&p.viewListing(this.data)},y}();!function(t){t.ALL="ALL",t.STATIC="STATIC",t.DISCOUNTED="DISCOUNTED",t.RECOMMENDED="RECOMMENDED",t.CATEGORY="CATEGORY",t.SEARCH="SEARCH",t.LAST_VIEWED="LAST_VIEWED",t.RELATED_PRODUCTS="RELATED_PRODUCTS"}(g||(g={})),function(t){t.INCREASING_PRICE="INCREASING_PRICE",t.DECREASING_PRICE="DECREASING_PRICE",t.LAST_ADDED="LAST_ADDED",t.FIRST_ADDED="FIRST_ADDED",t.INCREASING_DISCOUNT="INCREASING_DISCOUNT",t.DECRASING_DISCOUNT="DECRASING_DISCOUNT",t.FEATURED="FEATURED"}(_||(_={})),function(t){t.CATEGORY="CATEGORY",t.BRAND="BRAND"}(y||(y={}));export{v as IkasProductList,_ as IkasProductListSortType,g as IkasProductListType,y as IkasRelatedProductsType};
|
|
1
|
+
import{__awaiter as t,__generator as e}from'../../../ext/tslib/tslib.es6.js';import{makeAutoObservable as i}from"mobx";import"../../theme/theme.js";import{IkasThemePageType as r}from"../../theme/page/index.js";import"../../theme/component/prop/index.js";import"../../theme/page/component/prop-value/link.js";import"../brand-list/index.js";import"../blog-list/index.js";import"../blog-category-list/index.js";import"../category-list/index.js";import{IkasProductDetail as s}from"../product-detail/index.js";import"../product-attribute-detail/index.js";import"../product-attribute-list/index.js";import"../customer-review-list/index.js";import"../customer-review-summary-list/index.js";import"../validator/index.js";import"../validator/rules/index.js";import"../validator/form/login.js";import"../validator/form/address.js";import"../validator/form/register.js";import"../validator/form/contact-form.js";import"../validator/form/forgot-password.js";import"../validator/form/recover-password.js";import"../validator/form/account-info.js";import"../validator/form/raffle-form.js";import"../validator/form/customer-review.js";import"../raffle-list/index.js";import"../../theme/settings/index.js";import"../../theme/custom-data/index.js";import"../../../api/blog/index.js";import"../../../api/brand/index.js";import"../../../api/cart/index.js";import"../../../api/category/index.js";import"../../../api/checkout/index.js";import"../../../api/city/index.js";import"../../../api/country/index.js";import"../../../api/customer/index.js";import"../../../api/customer-review/index.js";import"../../../api/customer-review-summary/index.js";import"../../../api/district/index.js";import"../../../api/html-meta-data/index.js";import"../../../api/merchant/index.js";import{IkasProductSearchAPI as n}from"../../../api/product-search/index.js";import"../../data/blog/index.js";import"../../data/brand/index.js";import{ModelOrder as a,IkasFilterCategory as o}from"../../data/category/index.js";import"../../data/checkout/index.js";import"../../data/customer/address/index.js";import"../../data/customer/index.js";import"../../data/customer-review/index.js";import"../../data/html-meta-data/index.js";import"../../data/image/index.js";import"../../data/installment-info/index.js";import"../../data/merchant-settings/index.js";import"../../data/order/index.js";import"../../data/order/line-item/index.js";import"../../../api/product-option-file/index.js";import"../../data/product/index.js";import"../../data/variant-type/index.js";import"../../data/product/variant/index.js";import"../../data/product/variant/price/index.js";import"../../data/product-attribute/index.js";import"../../data/product/attribute-value/index.js";import{IkasProductFilter as u,IkasProductFilterValue as c}from"../../data/product-filter/index.js";import"../../data/variant-type/variant-value/index.js";import"../../data/order-transaction/index.js";import"../../data/product-option-set/index.js";import"../../data/raffle/index.js";import"../../data/product-campaing/campaign/index.js";import"../../data/customer-attribute/index.js";import"../../data/customer-attribute/customer-attribute-sales-channel/index.js";import"../../../api/apollo.js";import"../../../api/favorite-product/index.js";import"../../../api/contact-form/index.js";import"../../../api/state/index.js";import"../../../api/product-option-set/index.js";import"../../../api/raffle/index.js";import"../../../api/back-in-stock-reminder/index.js";import"../../../api/product-campaign/index.js";import l from'../../../ext/query-string/index.js';import d from'../../../ext/lodash/debounce.js';import{Analytics as p}from"../../../analytics/analytics.js";import"../../../analytics/head/index.js";import{IkasStorefrontConfig as h}from"../../../storefront/index.js";import{SortByDirectionEnum as f,SortByTypeEnum as m}from"../../../__generated__/global-types.js";var g,_,y,v=function(){function y(n,a){var c=this;if(this.filters=null,this._filterCategories=null,this._infiniteScrollPage=null,this._initialized=!1,this._minPage=null,this._filterBrandId=null,this._filterCategoryId=null,this._relatedProductData=null,this.pageSpecificData=null,this._recommendFor=null,this._isLoading=!1,this._fetchRequestTime=0,this.router=null,this.applyFilters=function(){return t(c,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,this.getInitial()];case 1:return t=e.sent(),[r.CATEGORY,r.BRAND,r.SEARCH].includes(this._pageType)?(t&&this.isBrowser()&&!this.isSearch&&!h.isEditor&&(null===(i=this.router)||void 0===i||i.replace("".concat(location.pathname).concat(this.filterQueryParams?"?"+this.filterQueryParams:""),void 0,{shallow:!0})),[2]):[2]}}))}))},this.getInitial=function(i,r){return t(c,void 0,void 0,(function(){var t,n,a,o,u,c,l,d,p;return e(this,(function(e){switch(e.label){case 0:this._isLoading=!0,t=Date.now(),this._fetchRequestTime=t,e.label=1;case 1:return e.trys.push([1,12,13,14]),n=r?this._page:1,a=this._limit,!this.isFilterable||this.filters?[3,3]:[4,this.getFilters()];case 2:e.sent(),e.label=3;case 3:return this.applyQueryParamFilters(i),this.isSearch&&!this.hasAppliedfilter?(this.data=[],this._page=1,this._minPage=1,this._count=0,this._initialized=!0,[2,!0]):(o=void 0,this.isStatic?(n=void 0,a=200,[3,10]):[3,4]);case 4:return this.isDiscounted?(n=1,a=10,[3,10]):[3,5];case 5:return this.isRecommended?(n=1,a=10,[3,10]):[3,6];case 6:return this.isLastViewed?this.isBrowser()?[4,this.waitForCustomerStoreInit()]:[3,9]:[3,10];case 7:return e.sent(),[4,h.store.customerStore.getLastViewedProducts()];case 8:return(u=e.sent())&&u.length&&(o=u.map((function(t){return t.productId}))),[3,10];case 9:return[2];case 10:return[4,this.searchProducts(n||1,a||10,o)];case 11:return(c=e.sent())&&this._fetchRequestTime===t?(l=[],this.isStatic||this.isLastViewed?(d=this.isStatic?this._productListPropValue.productIds:h.store.customerStore._lastViewedProducts,l=(null==d?void 0:d.map((function(t){var e=c.data.find((function(e){return e.id===t.productId})),i=null==e?void 0:e.variants.find((function(e){return e.id===t.variantId}));if((null==i?void 0:i.isActive)||(i=null==e?void 0:e.variants.find((function(t){return t.isActive}))),e&&i)return new s(e,i.variantValues)})).filter((function(t){return!!t})))||[]):l=c.data.map((function(t){var e=t.variants.find((function(t){return t.isActive}));return new s(t,(e||t.variants[0]).variantValues)})),this.applyFacets(c.facets),this.data=l,this._count=c.count,this._initialized=!0,this._page=n||1,this._minPage=this.page,r||(this._infiniteScrollPage=null),this.handleListingEvent(),[2,!0]):[2];case 12:return p=e.sent(),console.log(p),[3,14];case 13:return t===this._fetchRequestTime&&(this._isLoading=!1),[7];case 14:return[2]}}))}))},this.getPrev=function(){return t(c,void 0,void 0,(function(){var t,i,r,n;return e(this,(function(e){switch(e.label){case 0:if(this.isStatic||this.isDiscounted||this.isRecommended||this.isLastViewed||this._isLoading||!this.hasPrev)return[2];this._isLoading=!0,e.label=1;case 1:return e.trys.push([1,3,4,5]),t=this._minPage-1,[4,this.searchProducts(t,this.limit)];case 2:return(i=e.sent())?(r=i.data.map((function(t){var e=t.variants.find((function(t){return t.isActive}));return new s(t,(e||t.variants[0]).variantValues)})),this.data=r.concat(this.data),this._count=i.count,this._minPage=t,[3,5]):[2];case 3:return n=e.sent(),console.log(n),[3,5];case 4:return this._isLoading=!1,[7];case 5:return[2]}}))}))},this.getNext=function(){return t(c,void 0,void 0,(function(){var t,i,r;return e(this,(function(e){switch(e.label){case 0:if(this.isStatic||this.isDiscounted||this.isRecommended||this.isLastViewed||this._isLoading||!this.hasNext)return[2];this._isLoading=!0,e.label=1;case 1:return e.trys.push([1,3,4,5]),[4,this.searchProducts(this.page+1,this.limit)];case 2:return(t=e.sent())?(i=t.data.map((function(t){var e=t.variants.find((function(t){return t.isActive}));return new s(t,(e||t.variants[0]).variantValues)})),this.data=this.data.concat(i),this._count=t.count,this._page=this.page+1,[3,5]):[2];case 3:return r=e.sent(),console.log(r),[3,5];case 4:return this._isLoading=!1,[7];case 5:return[2]}}))}))},this.getPage=function(i){return t(c,void 0,void 0,(function(){var t,r,n;return e(this,(function(e){switch(e.label){case 0:if(this._isLoading||this.isStatic||this.isDiscounted||this.isRecommended||this.isLastViewed)return[2];this._isLoading=!0,e.label=1;case 1:return e.trys.push([1,3,4,5]),[4,this.searchProducts(i,this.limit)];case 2:return(t=e.sent())?(r=t.data.map((function(t){var e=t.variants.find((function(t){return t.isActive}));return new s(t,(e||t.variants[0]).variantValues)})),this.data=r,this._count=t.count,this._page=i,this._minPage=i,[3,5]):[2];case 3:return n=e.sent(),console.log(n),[3,5];case 4:return this._isLoading=!1,[7];case 5:return[2]}}))}))},this.setVisibleInfiniteScrollPage=function(t){var e;c._infiniteScrollPage!==t&&(c._infiniteScrollPage=t,h.isEditor||null===(e=c.router)||void 0===e||e.replace("".concat(location.pathname).concat(c.filterQueryParams?"?"+c.filterQueryParams:""),void 0,{shallow:!0}))},this.searchDebouncer=d((function(){c.applyFilters()}),100),this.searchAnalyticsDebouncer=d((function(){p.search(c._searchKeyword)}),1e3),this.data=n.data?n.data.map((function(t){return new s(t.product,t.selectedVariantValues)})):[],this._type=n.type||n.productListPropValue.productListType||g.ALL,this._pageType=n.pageType,this._sort=n.sort||n.productListPropValue.initialSort||_.LAST_ADDED,"A_Z"!==this.initialSort&&"Z_A"!==this.initialSort||(this._sort=_.LAST_ADDED),this._limit=n.limit||n.productListPropValue.initialLimit||20,this._page=n.page||1,this._minPage=n.minPage||null,this._count=n.count||0,this._searchKeyword=n.searchKeyword||"",this._productListPropValue=n.productListPropValue,this._filterBrandId=n.filterBrandId||null,this._filterCategoryId=n.filterCategoryId||null,this._relatedProductData=n.relatedProductData||null,this._recommendFor=n.recommendFor,this.filters=n.filters?n.filters.map((function(t){return new u(t,c)})):null,this._filterCategories=n.filterCategories?n.filterCategories.map((function(t){return new o(t)})):null,this.pageSpecificData=n.pageSpecificData||null,this.router=a,i(this),this.setPageSpecificSort(),this.isBrowser())if(this.restoreInfiniteScrollPage(),location.search&&(this.isFilterable||this._type===g.SEARCH)){var l=this.getQueryParams();this.getInitial(l,this._page>1)}else this._page>1?this.getInitial(void 0,!0):this.isLastViewed?this.getInitial():this.handleListingEvent()}return Object.defineProperty(y.prototype,"sort",{get:function(){return this._sort},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"limit",{get:function(){return this._limit},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"pageType",{get:function(){return this._pageType},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"page",{get:function(){return this._page},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"minPage",{get:function(){return this._minPage||1},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"count",{get:function(){return this._count},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"pageCount",{get:function(){return Math.ceil(this._count/this._limit)},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"searchKeyword",{get:function(){return this._searchKeyword},set:function(t){t!==this._searchKeyword&&(this._searchKeyword=t,this.searchDebouncer(),this.searchAnalyticsDebouncer())},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isInitialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isFilterable",{get:function(){return this._type===g.ALL||this._type===g.CATEGORY},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isFiltered",{get:function(){var t,e;return(null===(t=this.filters)||void 0===t?void 0:t.some((function(t){return!!t.valueList.length})))||!!this._searchKeyword||this._pageType!==r.CATEGORY&&(!!this._filterCategoryId||(null===(e=this._filterCategories)||void 0===e?void 0:e.some((function(t){return t.isSelected}))))},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isStatic",{get:function(){return this._type===g.STATIC},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isDiscounted",{get:function(){return this._type===g.DISCOUNTED},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isRecommended",{get:function(){return this._type===g.RECOMMENDED},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isLastViewed",{get:function(){return this._type===g.LAST_VIEWED},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isRelatedProducts",{get:function(){return this._type===g.RELATED_PRODUCTS},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isSearch",{get:function(){return this._type===g.SEARCH},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"hasPrev",{get:function(){return!(this.isStatic||this.isDiscounted||this.isRecommended||!this._minPage)&&this._minPage>1},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"hasNext",{get:function(){return!(this.isStatic||this.isDiscounted||this.isRecommended)&&this.page*this.limit<this.count},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isLoading",{get:function(){return this._isLoading},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"filterQueryParams",{get:function(){var t,e,i,s,n=this,a={},o=this.getQueryParams();if(o&&o.forEach((function(t,e){"s"!==e&&(a[e]=t)})),null===(t=this.filters)||void 0===t||t.forEach((function(t){t.keyList.length&&(a[t.key]=t.keyList)})),this._searchKeyword&&(a.s=this._searchKeyword),this._infiniteScrollPage&&(a.page=this._infiniteScrollPage),this._pageType!==r.CATEGORY){var u=null===(e=this.filterCategories)||void 0===e?void 0:e.filter((function(t){return t.isSelected}));if(!!(null==u?void 0:u.length))a.c=null==u?void 0:u.map((function(t){return t.slug}));else if(this._filterCategoryId){var c=null===(s=null===(i=this.filterCategories)||void 0===i?void 0:i.find((function(t){return t.id===n._filterCategoryId})))||void 0===s?void 0:s.slug;c&&(a.c=c)}}return l.stringify(a,{arrayFormat:"comma"})},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"filterCategories",{get:function(){var t;return null===(t=this._filterCategories)||void 0===t?void 0:t.filter((function(t){return 0!==t.resultCount}))},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"hasAppliedfilter",{get:function(){var t;return!!this._searchKeyword||(null===(t=this.filters)||void 0===t?void 0:t.some((function(t){return!!t.valueList.length})))},enumerable:!1,configurable:!0}),Object.defineProperty(y.prototype,"isFeaturedSortEnabled",{get:function(){var t;return(null===(t=this.pageSpecificData)||void 0===t?void 0:t.orderType)===a.MANUALLY&&[g.ALL,g.CATEGORY].includes(this._type)},enumerable:!1,configurable:!0}),y.prototype.setPageSpecificSort=function(){var t;if((null===(t=this.pageSpecificData)||void 0===t?void 0:t.orderType)&&[g.ALL,g.CATEGORY].includes(this._type))switch(this.pageSpecificData.orderType){case a.HIGHEST_DISCOUNT_RATIO:this._sort=_.DECRASING_DISCOUNT;break;case a.LOWEST_DISCOUNT_RATIO:this._sort=_.INCREASING_DISCOUNT;break;case a.HIGHEST_PRICE:this._sort=_.DECREASING_PRICE;break;case a.LOWEST_PRICE:this._sort=_.INCREASING_PRICE;break;case a.NEWEST:this._sort=_.LAST_ADDED;break;case a.OLDEST:this._sort=_.FIRST_ADDED;break;case a.MANUALLY:this._sort=_.FEATURED}},y.prototype.getSortParams=function(){var t=f.DESC,e=m.CREATED_AT;switch(this._sort){case _.INCREASING_PRICE:t=f.ASC,e=m.PRICE;break;case _.DECREASING_PRICE:t=f.DESC,e=m.PRICE;break;case _.FIRST_ADDED:t=f.ASC,e=m.CREATED_AT;break;case _.LAST_ADDED:t=f.DESC,e=m.CREATED_AT;break;case _.INCREASING_DISCOUNT:t=f.ASC,e=m.DISCOUNT_RATIO;break;case _.DECRASING_DISCOUNT:t=f.DESC,e=m.DISCOUNT_RATIO;break;case _.FEATURED:if(this.isSearch)return;t=f.ASC,e=m.MANUAL_SORT}return{direction:t,type:e}},y.prototype.searchProducts=function(i,s,a){var o,u,l;return t(this,void 0,void 0,(function(){var t,d,p,f;return e(this,(function(e){switch(e.label){case 0:return t=[],d=[],null===(o=this.filters)||void 0===o||o.forEach((function(e){e.valueList.length&&t.push(new c({id:e.id,type:e.type,displayType:e.displayType,valueList:e.valueList})),e.isFacetFilter&&d.push({id:e.id,type:e.type,displayType:e.displayType})})),p=null===(u=this._filterCategories)||void 0===u?void 0:u.filter((function(t){return t.isSelected})).map((function(t){return t.id})),f=this.getSortParams(),this.isRelatedProducts&&this._relatedProductData?[4,n.getRelatedProducts({priceListId:h.priceListId,salesChannelId:h.salesChannelId,productId:this._relatedProductData.productId,brandIds:this._relatedProductData.brandIds,categoryIds:this._relatedProductData.categoryIds})]:[3,2];case 1:case 3:return[2,e.sent()];case 2:return[4,n.searchProducts({page:i,perPage:s,productIdList:this.isStatic?null===(l=this._productListPropValue.productIds)||void 0===l?void 0:l.map((function(t){return t.productId})):a,filterList:t,facetList:d,brandId:this._pageType===r.BRAND&&this._type!==g.SEARCH?this._filterBrandId:void 0,categoryIdList:p&&p.length?p:this._filterCategoryId?[this._filterCategoryId]:void 0,priceListId:h.priceListId,salesChannelId:h.salesChannelId,query:this._searchKeyword,order:this._type===g.SEARCH?null:f?[f]:null},!0)]}}))}))},y.prototype.getFilters=function(){var i;return t(this,void 0,void 0,(function(){var t,s,a=this;return e(this,(function(e){switch(e.label){case 0:return[4,n.getProductFilterData(this._filterCategoryId?this._filterCategoryId:void 0)];case 1:return t=e.sent(),this.filters=null==t?void 0:t.filters.map((function(t){return new u(t,a)})),this._filterCategories=null==t?void 0:t.categories,this.pageType!==r.CATEGORY&&this._filterCategoryId&&(s=null===(i=this._filterCategories)||void 0===i?void 0:i.find((function(t){return t.id===a._filterCategoryId})))&&(s._isSelected=!0),this.filters&&this.filters.sort((function(t,e){return t.order>e.order?1:-1})),[2]}}))}))},y.prototype.applyQueryParamFilters=function(t){var e,i=this;try{null==t||t.forEach((function(t,e){var r,s=null===(r=i.filters)||void 0===r?void 0:r.find((function(t){return t.key===e}));s&&s.applyQueryParam(t)}));var s=null==t?void 0:t.get("s");if(s&&(this._searchKeyword=s),this._pageType!==r.CATEGORY){var n=null==t?void 0:t.get("c"),a=null==n?void 0:n.split(",");a&&a.length&&(null===(e=this.filterCategories)||void 0===e||e.forEach((function(t){t._isSelected=a.some((function(e){return e===t.slug}))})))}}catch(t){console.log(t)}},y.prototype.applyFacets=function(t){var e,i;null===(e=this.filters)||void 0===e||e.forEach((function(e){var i,r,s,n=null==t?void 0:t.find((function(t){return t.id===e.id}));n?null===(i=e.values)||void 0===i||i.forEach((function(t){var i=n.values.find((function(e){return e.id===t.id}));i?t.resultCount=i.count:e.isCustomValueFilter?t.resultCount=null:t.resultCount=0})):e.isCustomValueFilter?null===(r=e.values)||void 0===r||r.forEach((function(t){return t.resultCount=null})):null===(s=e.values)||void 0===s||s.forEach((function(t){return t.resultCount=0}))}));var r=null==t?void 0:t.find((function(t){return"category"===t.id}));r&&(null===(i=this._filterCategories)||void 0===i||i.forEach((function(t){var e=r.values.find((function(e){return e.id===t.id}));t.resultCount=e?e.count:0})))},y.prototype.clearFilters=function(){var t,e;null===(t=this.filters)||void 0===t||t.forEach((function(t){return t.clear()})),this._searchKeyword="",this._pageType!==r.CATEGORY&&(this._filterCategoryId=void 0),null===(e=this._filterCategories)||void 0===e||e.forEach((function(t){return t._isSelected=!1})),this.applyFilters()},y.prototype.setSortType=function(i){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this._sort=i,[4,this.getInitial()];case 1:return t.sent(),[2]}}))}))},y.prototype.onFilterCategoryClick=function(i,r){var s,n;return void 0===r&&(r=!1),t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return r?(null===(s=this._filterCategories)||void 0===s||s.forEach((function(t){t.id===i.id&&(t._isSelected=!t.isSelected)})),[4,this.applyFilters()]):[3,2];case 1:return t.sent(),[3,3];case 2:h.isEditor||null===(n=this.router)||void 0===n||n.push(i.href+(this.filterQueryParams?"?"+this.filterQueryParams:"")),t.label=3;case 3:return[2]}}))}))},y.prototype.toJSON=function(){return{data:this.data,type:this._type,pageType:this._pageType,sort:this._sort,limit:this._limit,page:this._page,count:this._count,searchKeyword:this._searchKeyword,initialized:this._initialized,minPage:this._minPage,filterBrandId:this._filterBrandId,filterCategoryId:this._filterCategoryId,filterCategories:this._filterCategories,filters:this.filters,recommendFor:this._recommendFor,productListPropValue:this._productListPropValue,pageSpecificData:this.pageSpecificData}},y.prototype.restoreInfiniteScrollPage=function(){var t=this.getQueryParams(),e=null==t?void 0:t.get("page");if(e){var i=parseInt(e);isNaN(i)||(this._page=i,this._infiniteScrollPage=i)}},y.prototype.getQueryParams=function(){if(this.isBrowser())return new URLSearchParams(location.search)},y.prototype.isBrowser=function(){return"undefined"!=typeof window},y.prototype.waitForCustomerStoreInit=function(){return new Promise((function(t){var e=setInterval((function(){h.store.customerStore.initialized&&(clearInterval(e),t(null))}),1e3)}))},y.prototype.handleListingEvent=function(){this.searchKeyword&&this.data.length?p.viewSearchResults(this._searchKeyword,this.data):this.data.length&&this._type===g.ALL&&p.viewListing(this.data)},y}();!function(t){t.ALL="ALL",t.STATIC="STATIC",t.DISCOUNTED="DISCOUNTED",t.RECOMMENDED="RECOMMENDED",t.CATEGORY="CATEGORY",t.SEARCH="SEARCH",t.LAST_VIEWED="LAST_VIEWED",t.RELATED_PRODUCTS="RELATED_PRODUCTS"}(g||(g={})),function(t){t.INCREASING_PRICE="INCREASING_PRICE",t.DECREASING_PRICE="DECREASING_PRICE",t.LAST_ADDED="LAST_ADDED",t.FIRST_ADDED="FIRST_ADDED",t.INCREASING_DISCOUNT="INCREASING_DISCOUNT",t.DECRASING_DISCOUNT="DECRASING_DISCOUNT",t.FEATURED="FEATURED"}(_||(_={})),function(t){t.CATEGORY="CATEGORY",t.BRAND="BRAND"}(y||(y={}));export{v as IkasProductList,_ as IkasProductListSortType,g as IkasProductListType,y as IkasRelatedProductsType};
|
package/build/store/cart.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IkasCart } from "../models/data/cart";
|
|
2
2
|
import { IkasProductVariant, IkasOrderLineItem, IkasProduct } from "../models";
|
|
3
3
|
import { IkasBaseStore } from "./base";
|
|
4
|
+
import { SaveItemToCartCallbackType } from "src/api/cart";
|
|
4
5
|
export declare const CART_LS_KEY = "cartId";
|
|
5
6
|
export declare const CHECKOUT_LS_KEY = "checkoutId";
|
|
6
7
|
export declare class IkasCartStore {
|
|
@@ -14,8 +15,29 @@ export declare class IkasCartStore {
|
|
|
14
15
|
get cartLoadFinished(): boolean;
|
|
15
16
|
get checkoutId(): string | null | undefined;
|
|
16
17
|
get checkoutUrl(): string | undefined;
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* @async
|
|
20
|
+
* @function addItem
|
|
21
|
+
* @param variant
|
|
22
|
+
* @param product
|
|
23
|
+
* @param initialQuantity
|
|
24
|
+
* @param {Function=} callback BREAKING CHANGE ALERT. will be deprecated in v3.0 -
|
|
25
|
+
* you can use when you want catch and handle api errors.
|
|
26
|
+
* for example max_quantity_per_cart_limit_reached
|
|
27
|
+
* @returns {Promise<boolean>}
|
|
28
|
+
*/
|
|
29
|
+
addItem: (variant: IkasProductVariant, product: IkasProduct, initialQuantity?: number, callback?: SaveItemToCartCallbackType | undefined) => Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* @async
|
|
32
|
+
* @function changeItemQuantity
|
|
33
|
+
* @param item
|
|
34
|
+
* @param quantity
|
|
35
|
+
* @param {Function=} callback BREAKING CHANGE ALERT. will be deprecated in v3.0 -
|
|
36
|
+
* you can use when you want catch and handle api errors.
|
|
37
|
+
* for example max_quantity_per_cart_limit_reached
|
|
38
|
+
* @returns {Promise<boolean>}
|
|
39
|
+
*/
|
|
40
|
+
changeItemQuantity: (item: IkasOrderLineItem, quantity: number, callback?: SaveItemToCartCallbackType | undefined) => Promise<boolean>;
|
|
19
41
|
removeItem: (item: IkasOrderLineItem) => Promise<void>;
|
|
20
42
|
removeCart: () => void;
|
|
21
43
|
waitUntilInitialized: () => Promise<unknown>;
|
package/build/store/cart.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as t,__generator as e}from'../ext/tslib/tslib.es6.js';import"../api/blog/index.js";import"../api/brand/index.js";import{IkasCartAPI as i}from"../api/cart/index.js";import"../api/category/index.js";import{IkasCheckoutAPI as o}from"../api/checkout/index.js";import"../api/city/index.js";import"../api/country/index.js";import"../api/customer/index.js";import"../api/customer-review/index.js";import"../api/customer-review-summary/index.js";import"../api/district/index.js";import"../api/html-meta-data/index.js";import"../api/merchant/index.js";import"../api/product-search/index.js";import"../models/data/blog/index.js";import"../models/data/brand/index.js";import"../models/data/category/index.js";import"../models/data/checkout/index.js";import"../models/data/customer/address/index.js";import"../models/data/customer/index.js";import"../models/data/customer-review/index.js";import{makeAutoObservable as r}from"mobx";import"../models/data/html-meta-data/index.js";import"../models/data/image/index.js";import"../models/data/installment-info/index.js";import"../models/data/merchant-settings/index.js";import"../models/data/order/index.js";import"../models/data/order/line-item/index.js";import"../api/product-option-file/index.js";import"../models/data/product/index.js";import"../models/data/variant-type/index.js";import"../models/data/product/variant/index.js";import"../models/data/product/variant/price/index.js";import"../models/data/product-attribute/index.js";import"../models/data/product/attribute-value/index.js";import"../models/data/product-filter/index.js";import"../models/data/variant-type/variant-value/index.js";import"../models/data/order-transaction/index.js";import"../models/data/product-option-set/index.js";import"../models/data/raffle/index.js";import"../models/data/product-campaing/campaign/index.js";import"../models/data/customer-attribute/index.js";import"../models/data/customer-attribute/customer-attribute-sales-channel/index.js";import"../models/theme/theme.js";import"../models/theme/page/index.js";import"../models/theme/component/prop/index.js";import"../models/theme/page/component/prop-value/link.js";import"../models/ui/brand-list/index.js";import"../models/ui/blog-list/index.js";import"../models/ui/blog-category-list/index.js";import"../models/ui/category-list/index.js";import"../models/ui/product-detail/index.js";import"../models/ui/product-list/index.js";import"../models/ui/product-attribute-detail/index.js";import"../models/ui/product-attribute-list/index.js";import"../models/ui/customer-review-list/index.js";import"../models/ui/customer-review-summary-list/index.js";import"../models/ui/validator/index.js";import"../models/ui/validator/rules/index.js";import"../models/ui/validator/form/login.js";import"../models/ui/validator/form/address.js";import"../models/ui/validator/form/register.js";import"../models/ui/validator/form/contact-form.js";import"../models/ui/validator/form/forgot-password.js";import"../models/ui/validator/form/recover-password.js";import"../models/ui/validator/form/account-info.js";import"../models/ui/validator/form/raffle-form.js";import"../models/ui/validator/form/customer-review.js";import"../models/ui/raffle-list/index.js";import"../models/theme/settings/index.js";import"../models/theme/custom-data/index.js";import"../api/apollo.js";import"../api/favorite-product/index.js";import"../api/contact-form/index.js";import"../api/state/index.js";import"../api/product-option-set/index.js";import"../api/raffle/index.js";import"../api/back-in-stock-reminder/index.js";import"../api/product-campaign/index.js";import{Analytics as n}from"../analytics/analytics.js";import"../analytics/head/index.js";import{IkasStorefrontConfig as a}from"../storefront/index.js";import{IkasProductCartLineOption as s}from"../models/data/product-cart-item-options/index.js";var d="cartId",c="checkoutId",u=function(){function d(d){var c=this;this.cart=null,this._checkoutId=null,this._isLoadingCart=!1,this._cartLoadFinished=!1,this.addItem=function(o,r,s){return void 0===s&&(s=1),t(c,void 0,void 0,(function(){var t,d,c,u,l,m,p,h,v,f,j,I,g;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),r.canAddToCart?[4,this.beforeCartOperationCheck()]:[2,!1];case 1:return e.sent(),this.cart&&(t=this.findExistingItem(o,r))?(null===(v=r.productOptionSet)||void 0===v||v.initOptionValues(),[2,this.changeItemQuantity(t,t.quantity+1)]):(d=this.getOptionValues(r),c=(null===(f=this.cart)||void 0===f?void 0:f.id)||localStorage.getItem("cartId"),u={cartId:c,customerId:(null===(j=this.cart)||void 0===j?void 0:j.customerId)||(null===(I=this.baseStore.customerStore.customer)||void 0===I?void 0:I.id)||null,item:{id:null,quantity:s,variant:{id:o.id,name:r.name}},options:d.length?d:null,priceListId:a.priceListId||null,salesChannelId:a.salesChannelId,storefrontId:a.storefrontId,storefrontRoutingId:a.storefrontRoutingId,storefrontThemeId:a.storefrontThemeId},[4,i.saveItemToCart(u)]);case 2:return(l=e.sent())?[4,this.setCart(l)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.cart&&(m="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(p=this.cart.items.find((function(t){return t.variant.id===o.id})))&&n.addToCart(p,s,m,this.cart)),null===(g=r.productOptionSet)||void 0===g||g.initOptionValues(),[2,!0];case 5:return h=e.sent(),console.log(h),[2,!1];case 6:return[2]}}))}))},this.changeItemQuantity=function(o,r){return t(c,void 0,void 0,(function(){var t,s,d,c,u,l,m,p;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={cartId:(null===(l=this.cart)||void 0===l?void 0:l.id)||null,customerId:(null===(m=this.cart)||void 0===m?void 0:m.customerId)||(null===(p=this.baseStore.customerStore.customer)||void 0===p?void 0:p.id)||null,item:{id:o.id,quantity:r,variant:{id:o.variant.id,name:o.variant.name}},options:this.createCartLineOptions(o),priceListId:a.priceListId||null,salesChannelId:a.salesChannelId,storefrontId:a.storefrontId,storefrontRoutingId:a.storefrontRoutingId,storefrontThemeId:a.storefrontThemeId},[4,i.saveItemToCart(t)];case 2:return(s=e.sent())?[4,this.setCart(s)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.removeCardIfEmpty(),this.cart&&(d="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(c=o.quantity)>r?n.removeFromCart(o,c-r,this.cart):n.addToCart(o,r-c,d,this.cart)),[2,!0];case 5:return u=e.sent(),console.log(u),[2,!1];case 6:return[2]}}))}))},this.removeItem=function(i){return t(c,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.changeItemQuantity(i,0)];case 1:return t.sent(),[2]}}))}))},this.removeCart=function(){localStorage.removeItem("cartId"),localStorage.removeItem("checkoutId"),c.cart=void 0,c._checkoutId=void 0},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){c.cartLoadFinished&&(clearInterval(e),t(null))}),100)}))},this.findExistingItem=function(t,e){var i,o,r,n,a;if(!e.productOptionSetId)return null===(i=c.cart)||void 0===i?void 0:i.items.find((function(e){return e.variant.id===t.id}));for(var s=c.getOptionValues(e),d=(null===(o=c.cart)||void 0===o?void 0:o.items.filter((function(e){var i;return e.variant.id===t.id&&(null===(i=e.options)||void 0===i?void 0:i.length)===s.length})))||[],u=0,l=d;u<l.length;u++){var m=l[u];if(m.options){for(var p=!0,h=function(t){var i=t.values.map((function(t){return t.value})),o=null===(a=null===(n=null===(r=e.productOptionSet)||void 0===r?void 0:r.options)||void 0===n?void 0:n.find((function(e){return e.id===t.productOptionId})))||void 0===a?void 0:a.values;if(!(p=p&&i.length===(null==o?void 0:o.length)&&i.every((function(t){return null==o?void 0:o.includes(t)}))))return"break"},v=0,f=m.options;v<f.length;v++){if("break"===h(f[v]))break}if(p)return m}}},this.removeCardIfEmpty=function(){var t;0===(null===(t=c.cart)||void 0===t?void 0:t.itemCount)&&c.removeCart()},this.getCart=function(){return t(c,void 0,void 0,(function(){var t,o,r,n,a,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===(a=this.baseStore.customerStore.customer)||void 0===a?void 0:a.id,(o=(null===(s=this.cart)||void 0===s?void 0:s.id)||localStorage.getItem("cartId"))||t?[4,i.getCart(o||void 0)]:[2];case 2:return(r=e.sent())?[4,this.setCart(r)]:[3,4];case 3:return e.sent(),[3,5];case 4:this.removeCart(),e.label=5;case 5:return[3,8];case 6:return n=e.sent(),console.log(n),[3,8];case 7:return this._isLoadingCart=!1,this._cartLoadFinished=!0,[7];case 8:return[2]}}))}))},this.setCart=function(i){return t(c,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return localStorage.setItem("cartId",i.id),this.cart=i,this._checkoutId||(this._checkoutId=localStorage.getItem("checkoutId")||void 0),this._checkoutId?[3,2]:[4,o.getCheckoutId(i.id)];case 1:t=e.sent(),this._checkoutId=t,t&&localStorage.setItem("checkoutId",t),e.label=2;case 2:return[2]}}))}))},this.beforeCartOperationCheck=function(){return t(c,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,o=t.options;i<o.length;i++){var r=o[i],n=new s({});n.productOptionId=r.productOptionId,n.productOptionsSetId=r.productOptionsSetId,n.values=r.values.map((function(t){return t.value})),e.push(n)}return e}return null},this.getOptionValues=function(t){var e,i=[];return null===(e=t.productOptionSet)||void 0===e||e.options.forEach((function(t){t.values.length&&i.push(new s({productOptionId:t.id,productOptionsSetId:t.productOptionSetId,values:t.values}))})),i},this.baseStore=d,r(this)}return Object.defineProperty(d.prototype,"isLoadingCart",{get:function(){return this._isLoadingCart},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"cartLoadFinished",{get:function(){return this._cartLoadFinished},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"checkoutId",{get:function(){return this._checkoutId},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"checkoutUrl",{get:function(){if(this._checkoutId)return"/checkout?id=".concat(this._checkoutId,"&step=info")},enumerable:!1,configurable:!0}),d}();export{d as CART_LS_KEY,c as CHECKOUT_LS_KEY,u as IkasCartStore};
|
|
1
|
+
import{__awaiter as t,__generator as e}from'../ext/tslib/tslib.es6.js';import"../api/blog/index.js";import"../api/brand/index.js";import{IkasCartAPI as i}from"../api/cart/index.js";import"../api/category/index.js";import{IkasCheckoutAPI as o}from"../api/checkout/index.js";import"../api/city/index.js";import"../api/country/index.js";import"../api/customer/index.js";import"../api/customer-review/index.js";import"../api/customer-review-summary/index.js";import"../api/district/index.js";import"../api/html-meta-data/index.js";import"../api/merchant/index.js";import"../api/product-search/index.js";import"../models/data/blog/index.js";import"../models/data/brand/index.js";import"../models/data/category/index.js";import"../models/data/checkout/index.js";import"../models/data/customer/address/index.js";import"../models/data/customer/index.js";import"../models/data/customer-review/index.js";import{makeAutoObservable as r}from"mobx";import"../models/data/html-meta-data/index.js";import"../models/data/image/index.js";import"../models/data/installment-info/index.js";import"../models/data/merchant-settings/index.js";import"../models/data/order/index.js";import"../models/data/order/line-item/index.js";import"../api/product-option-file/index.js";import"../models/data/product/index.js";import"../models/data/variant-type/index.js";import"../models/data/product/variant/index.js";import"../models/data/product/variant/price/index.js";import"../models/data/product-attribute/index.js";import"../models/data/product/attribute-value/index.js";import"../models/data/product-filter/index.js";import"../models/data/variant-type/variant-value/index.js";import"../models/data/order-transaction/index.js";import"../models/data/product-option-set/index.js";import"../models/data/raffle/index.js";import"../models/data/product-campaing/campaign/index.js";import"../models/data/customer-attribute/index.js";import"../models/data/customer-attribute/customer-attribute-sales-channel/index.js";import"../models/theme/theme.js";import"../models/theme/page/index.js";import"../models/theme/component/prop/index.js";import"../models/theme/page/component/prop-value/link.js";import"../models/ui/brand-list/index.js";import"../models/ui/blog-list/index.js";import"../models/ui/blog-category-list/index.js";import"../models/ui/category-list/index.js";import"../models/ui/product-detail/index.js";import"../models/ui/product-list/index.js";import"../models/ui/product-attribute-detail/index.js";import"../models/ui/product-attribute-list/index.js";import"../models/ui/customer-review-list/index.js";import"../models/ui/customer-review-summary-list/index.js";import"../models/ui/validator/index.js";import"../models/ui/validator/rules/index.js";import"../models/ui/validator/form/login.js";import"../models/ui/validator/form/address.js";import"../models/ui/validator/form/register.js";import"../models/ui/validator/form/contact-form.js";import"../models/ui/validator/form/forgot-password.js";import"../models/ui/validator/form/recover-password.js";import"../models/ui/validator/form/account-info.js";import"../models/ui/validator/form/raffle-form.js";import"../models/ui/validator/form/customer-review.js";import"../models/ui/raffle-list/index.js";import"../models/theme/settings/index.js";import"../models/theme/custom-data/index.js";import"../api/apollo.js";import"../api/favorite-product/index.js";import"../api/contact-form/index.js";import"../api/state/index.js";import"../api/product-option-set/index.js";import"../api/raffle/index.js";import"../api/back-in-stock-reminder/index.js";import"../api/product-campaign/index.js";import{Analytics as n}from"../analytics/analytics.js";import"../analytics/head/index.js";import{IkasStorefrontConfig as a}from"../storefront/index.js";import{IkasProductCartLineOption as s}from"../models/data/product-cart-item-options/index.js";var d="cartId",c="checkoutId",u=function(){function d(d){var c=this;this.cart=null,this._checkoutId=null,this._isLoadingCart=!1,this._cartLoadFinished=!1,this.addItem=function(o,r,s,d){return void 0===s&&(s=1),t(c,void 0,void 0,(function(){var t,c,u,l,m,p,h,v,f,j,I,g,x;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),r.canAddToCart?[4,this.beforeCartOperationCheck()]:[2,!1];case 1:return e.sent(),this.cart&&(t=this.findExistingItem(o,r))?(null===(f=r.productOptionSet)||void 0===f||f.initOptionValues(),[2,this.changeItemQuantity(t,t.quantity+1,d)]):(c=this.getOptionValues(r),u=(null===(j=this.cart)||void 0===j?void 0:j.id)||localStorage.getItem("cartId"),l={cartId:u,customerId:(null===(I=this.cart)||void 0===I?void 0:I.customerId)||(null===(g=this.baseStore.customerStore.customer)||void 0===g?void 0:g.id)||null,item:{id:null,quantity:s,variant:{id:o.id,name:r.name}},options:c.length?c:null,priceListId:a.priceListId||null,salesChannelId:a.salesChannelId,storefrontId:a.storefrontId,storefrontRoutingId:a.storefrontRoutingId,storefrontThemeId:a.storefrontThemeId},[4,i.saveItemToCart(l,d)]);case 2:return(m=e.sent())?[4,this.setCart(m)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.cart&&(p="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(h=this.cart.items.find((function(t){return t.variant.id===o.id})))&&n.addToCart(h,s,p,this.cart)),null===(x=r.productOptionSet)||void 0===x||x.initOptionValues(),[2,!0];case 5:return v=e.sent(),console.log(v),[2,!1];case 6:return[2]}}))}))},this.changeItemQuantity=function(o,r,s){return t(c,void 0,void 0,(function(){var t,d,c,u,l,m,p,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={cartId:(null===(m=this.cart)||void 0===m?void 0:m.id)||null,customerId:(null===(p=this.cart)||void 0===p?void 0:p.customerId)||(null===(h=this.baseStore.customerStore.customer)||void 0===h?void 0:h.id)||null,item:{id:o.id,quantity:r,variant:{id:o.variant.id,name:o.variant.name}},options:this.createCartLineOptions(o),priceListId:a.priceListId||null,salesChannelId:a.salesChannelId,storefrontId:a.storefrontId,storefrontRoutingId:a.storefrontRoutingId,storefrontThemeId:a.storefrontThemeId},[4,i.saveItemToCart(t,s)];case 2:return(d=e.sent())?[4,this.setCart(d)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.removeCardIfEmpty(),this.cart&&(c="".concat(this.cart.id,"-").concat(this.cart.updatedAt),(u=o.quantity)>r?n.removeFromCart(o,u-r,this.cart):n.addToCart(o,r-u,c,this.cart)),[2,!0];case 5:return l=e.sent(),console.log(l),[2,!1];case 6:return[2]}}))}))},this.removeItem=function(i){return t(c,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.changeItemQuantity(i,0)];case 1:return t.sent(),[2]}}))}))},this.removeCart=function(){localStorage.removeItem("cartId"),localStorage.removeItem("checkoutId"),c.cart=void 0,c._checkoutId=void 0},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){c.cartLoadFinished&&(clearInterval(e),t(null))}),100)}))},this.findExistingItem=function(t,e){var i,o,r,n,a;if(!e.productOptionSetId)return null===(i=c.cart)||void 0===i?void 0:i.items.find((function(e){return e.variant.id===t.id}));for(var s=c.getOptionValues(e),d=(null===(o=c.cart)||void 0===o?void 0:o.items.filter((function(e){var i;return e.variant.id===t.id&&(null===(i=e.options)||void 0===i?void 0:i.length)===s.length})))||[],u=0,l=d;u<l.length;u++){var m=l[u];if(m.options){for(var p=!0,h=function(t){var i=t.values.map((function(t){return t.value})),o=null===(a=null===(n=null===(r=e.productOptionSet)||void 0===r?void 0:r.options)||void 0===n?void 0:n.find((function(e){return e.id===t.productOptionId})))||void 0===a?void 0:a.values;if(!(p=p&&i.length===(null==o?void 0:o.length)&&i.every((function(t){return null==o?void 0:o.includes(t)}))))return"break"},v=0,f=m.options;v<f.length;v++){if("break"===h(f[v]))break}if(p)return m}}},this.removeCardIfEmpty=function(){var t;0===(null===(t=c.cart)||void 0===t?void 0:t.itemCount)&&c.removeCart()},this.getCart=function(){return t(c,void 0,void 0,(function(){var t,o,r,n,a,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===(a=this.baseStore.customerStore.customer)||void 0===a?void 0:a.id,(o=(null===(s=this.cart)||void 0===s?void 0:s.id)||localStorage.getItem("cartId"))||t?[4,i.getCart(o||void 0)]:[2];case 2:return(r=e.sent())?[4,this.setCart(r)]:[3,4];case 3:return e.sent(),[3,5];case 4:this.removeCart(),e.label=5;case 5:return[3,8];case 6:return n=e.sent(),console.log(n),[3,8];case 7:return this._isLoadingCart=!1,this._cartLoadFinished=!0,[7];case 8:return[2]}}))}))},this.setCart=function(i){return t(c,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return localStorage.setItem("cartId",i.id),this.cart=i,this._checkoutId||(this._checkoutId=localStorage.getItem("checkoutId")||void 0),this._checkoutId?[3,2]:[4,o.getCheckoutId(i.id)];case 1:t=e.sent(),this._checkoutId=t,t&&localStorage.setItem("checkoutId",t),e.label=2;case 2:return[2]}}))}))},this.beforeCartOperationCheck=function(){return t(c,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,o=t.options;i<o.length;i++){var r=o[i],n=new s({});n.productOptionId=r.productOptionId,n.productOptionsSetId=r.productOptionsSetId,n.values=r.values.map((function(t){return t.value})),e.push(n)}return e}return null},this.getOptionValues=function(t){var e,i=[];return null===(e=t.productOptionSet)||void 0===e||e.options.forEach((function(t){t.values.length&&i.push(new s({productOptionId:t.id,productOptionsSetId:t.productOptionSetId,values:t.values}))})),i},this.baseStore=d,r(this)}return Object.defineProperty(d.prototype,"isLoadingCart",{get:function(){return this._isLoadingCart},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"cartLoadFinished",{get:function(){return this._cartLoadFinished},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"checkoutId",{get:function(){return this._checkoutId},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"checkoutUrl",{get:function(){if(this._checkoutId)return"/checkout?id=".concat(this._checkoutId,"&step=info")},enumerable:!1,configurable:!0}),d}();export{d as CART_LS_KEY,c as CHECKOUT_LS_KEY,u as IkasCartStore};
|