@ikas/storefront 6.1.0-beta.22 → 6.1.0-beta.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{__awaiter as t,__generator as e,__assign as i}from'./../../../ext/tslib/tslib.es6.js';import{makeAutoObservable as r}from"mobx";import s from"lodash/debounce";import"../../data/blog/category/index.js";import"../../data/blog/content/index.js";import"../../data/blog/meta-data/index.js";import"../../data/blog/tag/index.js";import"../../data/blog/index.js";import"../../data/brand/index.js";import{IkasThemeJsonPageType as o,IkasCategoryProductsOrderType as a,IkasThemeJsonStockPreference as n}from"@ikas/storefront-models";import"../../data/campaign-offer/index.js";import"../../data/cart/campaign-offer/index.js";import"../../data/cart/index.js";import"../../data/category/path-item/index.js";import"../../data/category/index.js";import"../../data/checkout/index.js";import"../../data/checkout-settings/index.js";import"../../data/city/index.js";import"../../data/country/index.js";import"../../data/customer/address/region/index.js";import"../../data/customer/address/index.js";import"../../data/customer/address/ikas-localized-customer-address.js";import"../../data/customer/attribute/index.js";import"../../data/customer/review/summary/index.js";import"../../data/customer/review/index.js";import"../../data/customer/index.js";import"../../data/customer-form-data-input/index.js";import"../../data/district/index.js";import"../../data/favorite-product/index.js";import{IkasFilterCategory as d}from"../../data/filter-category/index.js";import"../../data/html-meta-data/index.js";import"../../data/image/index.js";import"../../data/order/address/region/index.js";import"../../data/order/address/index.js";import"../../data/order/line-item/option/value/index.js";import"../../data/order/line-item/variant/value/index.js";import"../../data/order/line-item/variant/index.js";import"../../data/order/line-item/index.js";import"../../data/order/order-transaction-with-prices/index.js";import"../../data/order/package/index.js";import"../../data/order/transaction/index.js";import"../../data/order/index.js";import"../../data/payment-gateway/index.js";import"../../data/product/attribute-value/index.js";import{IkasProductFilter as c,IkasProductFilterValue as u}from"../../data/product/filter/index.js";import"../../data/product/campaign-offer/index.js";import"../../data/product/option-set/option/index.js";import"../../data/product/option-set/index.js";import"../../data/product/stock-location/index.js";import"../../data/product/variant/price/index.js";import"../../data/product/variant/index.js";import"../../data/variant-type/index.js";import{IkasProduct as l}from"../../data/product/index.js";import"../../data/raffle/index.js";import"../../data/shipping-zone/state/city/district/region/index.js";import"../../data/state/index.js";import"../../data/storefront-popup/storefront-popup-display-filter/index.js";import"../../data/storefront-popup/storefront-popup-display-settings/index.js";import"../../data/storefront-popup/storefront-popup-page-filter/index.js";import"../../data/storefront-popup/index.js";import"../../data/theme-json/index.js";import"../../data/theme-json/component/index.js";import"../../data/theme-json/custom-data/index.js";import"../../data/variant-type/variant-value/index.js";import"@ikas/localized-address";import p from"../../../store/product/index.js";import h from"query-string";import{SortByDirectionEnum as f,SortByTypeEnum as m,GetSuggestedProductsMethodEnum as g}from"@ikas/storefront-api";import{IkasStorefrontConfig as _}from"@ikas/storefront-config";import{Analytics as v}from"../../../analytics/analytics.js";import"../../../analytics/head/index.js";import"../../../components/page/index.js";import"../../../components/page/head.js";import"react";import"next/image.js";import{stringToSlug as y,IkasProductVariantFunctions as E}from"@ikas/storefront-model-functions";import"../../../components/link/index.js";import"../../../components/page-editor/loader/style.module.scss.js";import"../../../components/google-captcha/index.js";import"../blog-list/index.js";import"../blog-category-list/index.js";import"../brand-list/index.js";import"../category-list/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/ikas-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"../../../pages/home.js";import"../../../pages/_slug_/index.js";import"../../../pages/pages/_slug_.js";import"../../../pages/checkout.js";import"../../../pages/account/index.js";import"../../../pages/account/addresses.js";import"../../../pages/account/orders/index.js";import"../../../pages/account/orders/_id_.js";import"../../../pages/account/login.js";import"../../../pages/account/register.js";import"../../../pages/account/forgot-password.js";import"../../../pages/account/recover-password.js";import"../../../pages/cart.js";import"../../../pages/editor.js";import"../../../pages/account/favorite-products.js";import"../../../pages/search.js";import"next/error.js";import"../../../pages/blog/index.js";import"../../../pages/blog/_slug_.js";import"../../../pages/raffle/_slug_.js";import"../../../pages/raffle/index.js";import"../../../pages/account/raffles.js";import"../../../pages/account/activate.js";import{IkasBaseStore as I}from"../../../store/base.js";import"../../../store/customer/index.js";import"../../../store/cart/index.js";import"lodash/get";var S,C,P,T,A,D=function(){function S(a,n){var u=this;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._recommendedProductData=null,this._viewedTogetherProductData=null,this.pageSpecificData=null,this._recommendFor=null,this._isLoading=!1,this._fetchRequestTime=0,this.router=null,this._excludedFields=null,this._disabledSortTypes=null,this.applyFilters=function(){return t(u,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getInitial()];case 1:return t=e.sent(),[o.CATEGORY,o.BRAND,o.SEARCH].includes(this._pageType)?(t&&this.setQueryParams(),[2]):[2]}}))}))},this.getSelectedVariant=function(t){return t.variants[0]},this.getInitial=function(r,s){return t(u,void 0,void 0,(function(){var t,o,a,n,d,c,u,p,h,f,m,g,_,v,y,S=this;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,14,15,16]),o=s?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(r),this.isSearch&&!this.hasAppliedfilter?(this.data=[],this._page=1,this._minPage=1,this._count=0,this._initialized=!0,[2,!0]):(n=void 0,d=!1,this.isStatic?(o=void 0,a=200,[3,10]):[3,4]);case 4:return this.isDiscounted?(o=1,a=10,[3,10]):[3,5];case 5:return this.isRecommended?(o=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,I.getInstance().customerStore.getLastViewedProducts()];case 8:return(c=e.sent())&&c.length?(n=c.map((function(t){return t.productId})),d=I.getInstance().customerStore.useLastViewedProductResponse,[3,10]):[2];case 9:return[2];case 10:return d?(p=I.getInstance().customerStore._savedLastViewedProductsResponse,[3,13]):[3,11];case 11:return[4,this.searchProducts(o||1,a||10,n)];case 12:p=e.sent(),e.label=13;case 13:return(u=p)&&this._fetchRequestTime===t?(h=[],!d&&this.isLastViewed&&I.getInstance().customerStore.setSavedLastViewedProductsResponse(u),this.isStatic||this.isLastViewed?(f=this.isStatic?this._productListPropValue.productIds:I.getInstance().customerStore._lastViewedProducts,h=(null==f?void 0:f.map((function(t){var e,r,s=null===(r=null===(e=u.data)||void 0===e?void 0:e.data)||void 0===r?void 0:r.find((function(e){return e.id===t.productId})),o=null==s?void 0:s.variants.find((function(e){return e.id===t.variantId}));if((null==o?void 0:o.isActive)&&E.hasStock(o)||(o=null==s?void 0:s.variants.find((function(t){return t.isActive&&E.hasStock(t)}))),s&&o)return new l(i(i({},s),{selectedVariantValues:o.variantValues}))})).filter((function(t){return!!t})))||[]):h=(null===(_=null===(g=u.data)||void 0===g?void 0:g.data)||void 0===_?void 0:_.map((function(t){var e=S.getSelectedVariant(t);return new l(i(i({},t),{selectedVariantValues:e.variantValues}))})))||[],this.applyFacets(null===(v=u.data)||void 0===v?void 0:v.facets),this.data=h,this._count=(null===(y=u.data)||void 0===y?void 0:y.count)||0,this._initialized=!0,this._page=o||1,this._minPage=this.page,this.setIsFilteredForProducts(),this.setIsStaticForProducts(),s||(this._infiniteScrollPage=null),this.handleListingEvent(),[2,!0]):[2];case 14:return m=e.sent(),console.log(m),[3,16];case 15:return t===this._fetchRequestTime&&(this._isLoading=!1),[7];case 16:return[2]}}))}))},this.getPrev=function(){return t(u,void 0,void 0,(function(){var t,r,s,o,a,n,d,c=this;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(r=e.sent())?(s=null===(n=null===(a=r.data)||void 0===a?void 0:a.data)||void 0===n?void 0:n.map((function(t){var e=c.getSelectedVariant(t);return new l(i(i({},t),{selectedVariantValues:e.variantValues}))})),this.data=(null==s?void 0:s.concat(this.data))||this.data,this._count=(null===(d=r.data)||void 0===d?void 0:d.count)||this._count,this._minPage=t,this.setIsFilteredForProducts(),this.setIsStaticForProducts(),[3,5]):[2];case 3:return o=e.sent(),console.log(o),[3,5];case 4:return this._isLoading=!1,[7];case 5:return[2]}}))}))},this.getNext=function(){return t(u,void 0,void 0,(function(){var t,r,s,o,a,n,d=this;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())?(r=null===(a=null===(o=t.data)||void 0===o?void 0:o.data)||void 0===a?void 0:a.map((function(t){var e=d.getSelectedVariant(t);return new l(i(i({},t),{selectedVariantValues:e.variantValues}))})),this.data=this.data.concat(r||[]),this._count=(null===(n=t.data)||void 0===n?void 0:n.count)||this._count,this._page=this.page+1,this.setIsFilteredForProducts(),this.setIsStaticForProducts(),[3,5]):[2];case 3:return s=e.sent(),console.log(s),[3,5];case 4:return this._isLoading=!1,[7];case 5:return[2]}}))}))},this.getPage=function(r){return t(u,void 0,void 0,(function(){var t,s,o,a,n,d,c=this;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(r,this.limit)];case 2:return(t=e.sent())?(s=null===(n=null===(a=t.data)||void 0===a?void 0:a.data)||void 0===n?void 0:n.map((function(t){var e=c.getSelectedVariant(t);return new l(i(i({},t),{selectedVariantValues:e.variantValues}))})),this.data=s||[],this._count=(null===(d=t.data)||void 0===d?void 0:d.count)||0,this._page=r,this._minPage=r,this.setIsFilteredForProducts(),this.setIsStaticForProducts(),[3,5]):[2];case 3:return o=e.sent(),console.log(o),[3,5];case 4:return this._isLoading=!1,[7];case 5:return[2]}}))}))},this.setVisibleInfiniteScrollPage=function(t){var e;u._infiniteScrollPage!==t&&(u._infiniteScrollPage=t,_.getIsEditor()||null===(e=u.router)||void 0===e||e.replace("".concat(location.pathname).concat(u.queryParams?"?"+u.queryParams:""),void 0,{shallow:!0}))},this.searchDebouncer=s((function(){u.applyFilters()}),500),this.searchAnalyticsDebouncer=s((function(){v.search(u._searchKeyword,u.data.length)}),1e3);var p=a,h=a;if(this.data=a.data?a.data.map((function(t){return new l(t)})):[],this._type=p.type||h._type||p.productListPropValue.productListType||h._productListPropValue.productListType||C.ALL,this._pageType=a.pageType,this._sort=a.sort||a.productListPropValue.initialSort||P.LAST_ADDED,this._limit=a.limit||p.productListPropValue.initialLimit||h._productListPropValue.initialLimit||20,this._page=a.page||1,this._minPage=a.minPage||null,this._count=a.count||0,this._searchKeyword=a.searchKeyword||"",this._productListPropValue=p.productListPropValue||h._productListPropValue,this._filterBrandId=p.filterBrandId||h._filterBrandId||null,this._filterCategoryId=p.filterCategoryId||h._filterCategoryId||null,this._relatedProductData=p.relatedProductData||h._relatedProductData||null,this._recommendedProductData=p.recommendedProductData||h._recommendedProductData||null,this._viewedTogetherProductData=p.viewedTogetherProductData||h._viewedTogetherProductData||null,this._excludedFields=p.excludedFields||h._excludedFields||null,this._disabledSortTypes=p.disabledSortTypes||h._disabledSortTypes||null,this._recommendFor=p.recommendFor||h._recommendFor,this.filters=a.filters?a.filters.map((function(t){return new c(t,u)})):null,this._filterCategories=a.filterCategories?a.filterCategories.map((function(t){return new d(t)})):null,this.pageSpecificData=p.pageSpecificData||h.pageSpecificData||null,this.router=n,r(this,{router:!1}),this.setPageSpecificSort(),this.setIsFilteredForProducts(),this.setIsStaticForProducts(),this.isBrowser())if(this.restoreInfiniteScrollPage(),location.search&&(this.isFilterable||this._type===C.SEARCH)){var f=this.getQueryParams();this.getInitial(f,this._page>1)}else this._page>1?this.getInitial(void 0,!0):this.isLastViewed?this.getInitial():this.handleListingEvent()}return Object.defineProperty(S.prototype,"sort",{get:function(){return this._sort},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"limit",{get:function(){return this._limit},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"pageType",{get:function(){return this._pageType},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"page",{get:function(){return this._page},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"minPage",{get:function(){return this._minPage||1},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"count",{get:function(){return this._count},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"pageCount",{get:function(){return Math.ceil(this._count/this._limit)},enumerable:!1,configurable:!0}),Object.defineProperty(S.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(S.prototype,"isInitialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"isFilterable",{get:function(){return this._type===C.ALL||this._type===C.CATEGORY},enumerable:!1,configurable:!0}),Object.defineProperty(S.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!==o.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(S.prototype,"isStatic",{get:function(){return this._type===C.STATIC},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"isDiscounted",{get:function(){return this._type===C.DISCOUNTED},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"isRecommended",{get:function(){return this._type===C.RECOMMENDED},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"isLastViewed",{get:function(){return this._type===C.LAST_VIEWED},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"isRelatedProducts",{get:function(){return this._type===C.RELATED_PRODUCTS},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"isRecommendedProducts",{get:function(){return this._type===C.RECOMMENDED_PRODUCTS},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"isViewedTogetherProducts",{get:function(){return this._type===C.VIEWED_TOGETHER},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"isSearch",{get:function(){return this._type===C.SEARCH},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"hasPrev",{get:function(){return!(this.isStatic||this.isDiscounted||this.isRecommended||!this._minPage)&&this._minPage>1},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"hasNext",{get:function(){return!(this.isStatic||this.isDiscounted||this.isRecommended)&&this.page*this.limit<this.count},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"isLoading",{get:function(){return this._isLoading},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"queryParams",{get:function(){var t,e,i,r,s=this,a={};if(null===(t=this.filters)||void 0===t||t.forEach((function(t){t.keyList.length&&(a[y(t.name)]=t.keyList)})),this._searchKeyword&&(a.s=this._searchKeyword),this._sort&&(a.o=b[this._sort]),this._infiniteScrollPage&&(a.page=this._infiniteScrollPage),this._pageType!==o.CATEGORY){var n=null===(e=this.filterCategories)||void 0===e?void 0:e.filter((function(t){return t.isSelected}));if(!!(null==n?void 0:n.length))a.c=null==n?void 0:n.map((function(t){return t.slug}));else if(this._filterCategoryId){var d=null===(r=null===(i=this.filterCategories)||void 0===i?void 0:i.find((function(t){return t.id===s._filterCategoryId})))||void 0===r?void 0:r.slug;d&&(a.c=d)}}return h.stringify(a,{arrayFormat:"comma",encode:!1})},enumerable:!1,configurable:!0}),Object.defineProperty(S.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(S.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(S.prototype,"isFeaturedSortEnabled",{get:function(){var t;return(null===(t=this.pageSpecificData)||void 0===t?void 0:t.orderType)===a.MANUALLY&&[C.ALL,C.CATEGORY].includes(this._type)},enumerable:!1,configurable:!0}),Object.defineProperty(S.prototype,"disabledSortTypes",{get:function(){return this._disabledSortTypes},enumerable:!1,configurable:!0}),S.prototype.setIsFilteredForProducts=function(){var t=this;this.data.forEach((function(e){return e.isFiltered=t.isFiltered||!1}))},S.prototype.setIsStaticForProducts=function(){var t=this;this.data.forEach((function(e){return e.isStatic=t.isStatic||!1}))},S.prototype.setPageSpecificSort=function(){var t;if((null===(t=this.pageSpecificData)||void 0===t?void 0:t.orderType)&&[C.ALL].includes(this._type))switch(this.pageSpecificData.orderType){case a.HIGHEST_DISCOUNT_RATIO:this._sort=P.DECRASING_DISCOUNT;break;case a.LOWEST_DISCOUNT_RATIO:this._sort=P.INCREASING_DISCOUNT;break;case a.HIGHEST_PRICE:this._sort=P.DECREASING_PRICE;break;case a.LOWEST_PRICE:this._sort=P.INCREASING_PRICE;break;case a.NEWEST:this._sort=P.LAST_ADDED;break;case a.OLDEST:this._sort=P.FIRST_ADDED;break;case a.MANUALLY:this._sort=P.FEATURED}},S.prototype.getSortParams=function(){var t,e;switch(this._sort){case P.INCREASING_PRICE:t=f.ASC,e=m.PRICE;break;case P.DECREASING_PRICE:t=f.DESC,e=m.PRICE;break;case P.FIRST_ADDED:t=f.ASC,e=m.CREATED_AT;break;case P.LAST_ADDED:t=f.DESC,e=m.CREATED_AT;break;case P.INCREASING_DISCOUNT:t=f.ASC,e=m.DISCOUNT_RATIO;break;case P.DECRASING_DISCOUNT:t=f.DESC,e=m.DISCOUNT_RATIO;break;case P.FEATURED:if(this.isSearch)return;t=f.ASC,e=m.MANUAL_SORT;break;case P.DEFAULT:t=void 0,e=void 0;break;case P.AVERAGE_RATING:t=f.DESC,e=m.AVERAGE_RATING;break;case P.REVIEW_COUNT:t=f.DESC,e=m.REVIEW_COUNT;break;case P.SALE_COUNT:t=f.DESC,e=m.SALE_COUNT;break;case P.A_Z:t=f.ASC,e=m.NAME;break;case P.Z_A:t=f.DESC,e=m.NAME}if(t&&e)return{direction:t,type:e}},S.prototype.searchProducts=function(i,r,s){var a,d,c;return t(this,void 0,void 0,(function(){var t,l,h,f,m;return e(this,(function(e){switch(e.label){case 0:return t=[],l=[],null===(a=this.filters)||void 0===a||a.forEach((function(e){e.valueList.length&&t.push(new u({id:e.id,type:e.type,displayType:e.displayType,valueList:e.valueList})),e.isFacetFilter&&l.push({id:e.id,type:e.type,displayType:e.displayType})})),h=null===(d=this._filterCategories)||void 0===d?void 0:d.filter((function(t){return t.isSelected})).map((function(t){return t.id})),f=this.getSortParams(),this.isRelatedProducts&&this._relatedProductData?[4,p.getSuggestedProducts({priceListId:_.getPriceListId(),salesChannelId:_.getSalesChannelId(),productId:this._relatedProductData.productId,brandIds:this._relatedProductData.brandIds,categoryIds:this._relatedProductData.categoryIds,locale:_.getCurrentLocale()})]:[3,2];case 1:case 3:case 5:case 7:return[2,e.sent()];case 2:return this.isRecommendedProducts&&this._recommendedProductData?[4,p.getSuggestedProducts({priceListId:_.getPriceListId(),salesChannelId:_.getSalesChannelId(),brandIds:this._recommendedProductData.brandIds,categoryIds:this._recommendedProductData.categoryIds,locale:_.getCurrentLocale()})]:[3,4];case 4:return this.isViewedTogetherProducts&&this._viewedTogetherProductData?[4,p.getSuggestedProducts({priceListId:_.getPriceListId(),salesChannelId:_.getSalesChannelId(),method:g.VIEWED_TOGETHER,productIds:this._viewedTogetherProductData.productIds,locale:_.getCurrentLocale()})]:[3,6];case 6:return m={input:{page:i,perPage:r,productIdList:this.isStatic?null===(c=this._productListPropValue.productIds)||void 0===c?void 0:c.map((function(t){return t.productId})):s,filterList:t,facetList:l,brandId:this._pageType===o.BRAND&&this._type!==C.SEARCH?this._filterBrandId:void 0,categoryIdList:h&&h.length?h:this._filterCategoryId?[this._filterCategoryId]:void 0,priceListId:_.getPriceListId(),salesChannelId:_.getSalesChannelId(),query:this._searchKeyword,order:f?[f]:[],showStockOption:_.getStockPreference()||n.SHOW_ALL}},[4,p.searchProducts(m,this._excludedFields)]}}))}))},S.prototype.getFilters=function(){var i,r,s,a;return t(this,void 0,void 0,(function(){var t,n,d=this;return e(this,(function(e){switch(e.label){case 0:return[4,p.getProductFilterData({categoryId:this._filterCategoryId?this._filterCategoryId:void 0,locale:_.getCurrentLocale()})];case 1:return t=e.sent(),this.filters=null===(i=null==t?void 0:t.data)||void 0===i?void 0:i.filters.map((function(t){return new c(t,d)})),this._filterCategories=null===(r=null==t?void 0:t.data)||void 0===r?void 0:r.categories,this._disabledSortTypes=null===(s=t.data)||void 0===s?void 0:s.disabledSortTypes,this.pageType!==o.CATEGORY&&this._filterCategoryId&&(n=null===(a=this._filterCategories)||void 0===a?void 0:a.find((function(t){return t.id===d._filterCategoryId})))&&(n.isSelected=!0),this.filters&&this.filters.sort((function(t,e){return t.order>e.order?1:-1})),[2]}}))}))},S.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||t.name===e||y(t.name)===y(e)}));s&&s.applyQueryParam(t)}));var r=null==t?void 0:t.get("s");r&&(this._searchKeyword=r);var s=null==t?void 0:t.get("o");if(s){var a=parseInt(s),n=Object.entries(b).find((function(t){return t[1]===a}));n&&(this._sort=n[0])}if(this._pageType!==o.CATEGORY){var d=null==t?void 0:t.get("c"),c=null==d?void 0:d.split(",");c&&c.length&&(null===(e=this.filterCategories)||void 0===e||e.forEach((function(t){t.isSelected=c.some((function(e){return e===t.slug}))})))}}catch(t){console.log(t)}},S.prototype.applyFacets=function(t){var e,i;null===(e=this.filters)||void 0===e||e.forEach((function(e){var i,r,s,o=null==t?void 0:t.find((function(t){return t.id===e.id}));o?null===(i=e.values)||void 0===i||i.forEach((function(t){var i=o.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})))},S.prototype.setQueryParams=function(){var t;!this.isBrowser()||this.isSearch||_.getIsEditor()||null===(t=this.router)||void 0===t||t.replace("".concat(location.pathname).concat(this.queryParams?"?"+this.queryParams:""),void 0,{shallow:!0})},S.prototype.clearFilters=function(){var t,e;null===(t=this.filters)||void 0===t||t.forEach((function(t){return t.clear()})),this._searchKeyword="",this._pageType!==o.CATEGORY&&(this._filterCategoryId=void 0),null===(e=this._filterCategories)||void 0===e||e.forEach((function(t){return t.isSelected=!1})),this.applyFilters()},S.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()&&this.setQueryParams(),[2]}}))}))},S.prototype.onFilterCategoryClick=function(i,r){var s,o;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:_.getIsEditor()||null===(o=I.getInstance().router)||void 0===o||o.push(i.href+(this.queryParams?"?"+this.queryParams:"")),t.label=3;case 3:return[2]}}))}))},S.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}},S.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)}},S.prototype.getQueryParams=function(){if(this.isBrowser())return new URLSearchParams(location.search)},S.prototype.isBrowser=function(){return"undefined"!=typeof window},S.prototype.waitForCustomerStoreInit=function(){return new Promise((function(t){var e=setInterval((function(){I.getInstance().customerStore.initialized&&(clearInterval(e),t(null))}),1e3)}))},S.prototype.handleListingEvent=function(){this.searchKeyword&&this.data.length?v.viewSearchResults(this._searchKeyword,this.data):this.data.length&&this._type===C.ALL&&v.viewListing(this.data)},S}();!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",t.VIEWED_TOGETHER="VIEWED_TOGETHER",t.RECOMMENDED_PRODUCTS="RECOMMENDED_PRODUCTS"}(C||(C={})),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",t.DEFAULT="DEFAULT",t.AVERAGE_RATING="AVERAGE_RATING",t.REVIEW_COUNT="REVIEW_COUNT",t.SALE_COUNT="SALE_COUNT",t.A_Z="A_Z",t.Z_A="Z_A"}(P||(P={})),function(t){t.AVERAGE_RATING="AVERAGE_RATING",t.CREATED_AT="CREATED_AT",t.DISCOUNT_RATIO="DISCOUNT_RATIO",t.MANUAL_SORT="MANUAL_SORT",t.NAME="NAME",t.PRICE="PRICE",t.REVIEW_COUNT="REVIEW_COUNT",t.SALE_COUNT="SALE_COUNT"}(T||(T={})),function(t){t.CATEGORY="CATEGORY",t.BRAND="BRAND"}(A||(A={}));var b=((S={})[P.INCREASING_PRICE]=1,S[P.DECREASING_PRICE]=2,S[P.LAST_ADDED]=3,S[P.FIRST_ADDED]=4,S[P.INCREASING_DISCOUNT]=5,S[P.DECRASING_DISCOUNT]=6,S[P.FEATURED]=7,S[P.DEFAULT]=8,S[P.AVERAGE_RATING]=9,S[P.REVIEW_COUNT]=10,S[P.SALE_COUNT]=11,S[P.A_Z]=12,S[P.Z_A]=13,S);export{D as IkasProductList,T as IkasProductListSortByTypeEnum,P as IkasProductListSortType,C as IkasProductListType,A as IkasRelatedProductsType};
1
+ import{__awaiter as t,__generator as e,__assign as i}from'./../../../ext/tslib/tslib.es6.js';import{makeAutoObservable as r}from"mobx";import s from"lodash/debounce";import"../../data/blog/category/index.js";import"../../data/blog/content/index.js";import"../../data/blog/meta-data/index.js";import"../../data/blog/tag/index.js";import"../../data/blog/index.js";import"../../data/brand/index.js";import{IkasThemeJsonPageType as o,IkasCategoryProductsOrderType as a,IkasThemeJsonStockPreference as n}from"@ikas/storefront-models";import"../../data/campaign-offer/index.js";import"../../data/cart/campaign-offer/index.js";import"../../data/cart/index.js";import"../../data/category/path-item/index.js";import"../../data/category/index.js";import"../../data/checkout/index.js";import"../../data/checkout-settings/index.js";import"../../data/city/index.js";import"../../data/country/index.js";import"../../data/customer/address/region/index.js";import"../../data/customer/address/index.js";import"../../data/customer/address/ikas-localized-customer-address.js";import"../../data/customer/attribute/index.js";import"../../data/customer/review/summary/index.js";import"../../data/customer/review/index.js";import"../../data/customer/index.js";import"../../data/customer-form-data-input/index.js";import"../../data/district/index.js";import"../../data/favorite-product/index.js";import{IkasFilterCategory as d}from"../../data/filter-category/index.js";import"../../data/html-meta-data/index.js";import"../../data/image/index.js";import"../../data/order/address/region/index.js";import"../../data/order/address/index.js";import"../../data/order/line-item/option/value/index.js";import"../../data/order/line-item/variant/value/index.js";import"../../data/order/line-item/variant/index.js";import"../../data/order/line-item/index.js";import"../../data/order/order-transaction-with-prices/index.js";import"../../data/order/package/index.js";import"../../data/order/transaction/index.js";import"../../data/order/index.js";import"../../data/payment-gateway/index.js";import"../../data/product/attribute-value/index.js";import{IkasProductFilter as c,IkasProductFilterValue as u}from"../../data/product/filter/index.js";import"../../data/product/campaign-offer/index.js";import"../../data/product/option-set/option/index.js";import"../../data/product/option-set/index.js";import"../../data/product/stock-location/index.js";import"../../data/product/variant/price/index.js";import"../../data/product/variant/index.js";import"../../data/variant-type/index.js";import{IkasProduct as l}from"../../data/product/index.js";import"../../data/raffle/index.js";import"../../data/shipping-zone/state/city/district/region/index.js";import"../../data/state/index.js";import"../../data/storefront-popup/storefront-popup-display-filter/index.js";import"../../data/storefront-popup/storefront-popup-display-settings/index.js";import"../../data/storefront-popup/storefront-popup-page-filter/index.js";import"../../data/storefront-popup/index.js";import"../../data/theme-json/index.js";import"../../data/theme-json/component/index.js";import"../../data/theme-json/custom-data/index.js";import"../../data/variant-type/variant-value/index.js";import"@ikas/localized-address";import p from"../../../store/product/index.js";import h from"query-string";import{SortByDirectionEnum as f,SortByTypeEnum as m,GetSuggestedProductsMethodEnum as g}from"@ikas/storefront-api";import{IkasStorefrontConfig as _}from"@ikas/storefront-config";import{Analytics as v}from"../../../analytics/analytics.js";import"../../../analytics/head/index.js";import"../../../components/page/index.js";import"../../../components/page/head.js";import"react";import"next/image.js";import{stringToSlug as y,IkasProductVariantFunctions as E,IkasProductFilterFunctions as I}from"@ikas/storefront-model-functions";import"../../../components/link/index.js";import"../../../components/page-editor/loader/style.module.scss.js";import"../../../components/google-captcha/index.js";import"../blog-list/index.js";import"../blog-category-list/index.js";import"../brand-list/index.js";import"../category-list/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/ikas-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"../../../pages/home.js";import"../../../pages/_slug_/index.js";import"../../../pages/pages/_slug_.js";import"../../../pages/checkout.js";import"../../../pages/account/index.js";import"../../../pages/account/addresses.js";import"../../../pages/account/orders/index.js";import"../../../pages/account/orders/_id_.js";import"../../../pages/account/login.js";import"../../../pages/account/register.js";import"../../../pages/account/forgot-password.js";import"../../../pages/account/recover-password.js";import"../../../pages/cart.js";import"../../../pages/editor.js";import"../../../pages/account/favorite-products.js";import"../../../pages/search.js";import"next/error.js";import"../../../pages/blog/index.js";import"../../../pages/blog/_slug_.js";import"../../../pages/raffle/_slug_.js";import"../../../pages/raffle/index.js";import"../../../pages/account/raffles.js";import"../../../pages/account/activate.js";import{IkasBaseStore as S}from"../../../store/base.js";import"../../../store/customer/index.js";import"../../../store/cart/index.js";import"lodash/get";var C,P,T,A,D,b=function(){function C(a,n){var u=this;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._recommendedProductData=null,this._viewedTogetherProductData=null,this.pageSpecificData=null,this._recommendFor=null,this._isLoading=!1,this._fetchRequestTime=0,this.router=null,this._excludedFields=null,this._disabledSortTypes=null,this.applyFilters=function(){return t(u,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getInitial()];case 1:return t=e.sent(),[o.CATEGORY,o.BRAND,o.SEARCH].includes(this._pageType)?(t&&this.setQueryParams(),[2]):[2]}}))}))},this.getSelectedVariant=function(t){return t.variants[0]},this.getInitial=function(r,s){return t(u,void 0,void 0,(function(){var t,o,a,n,d,c,u,p,h,f,m,g,_,v,y,I=this;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,14,15,16]),o=s?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(r),this.isSearch&&!this.hasAppliedfilter?(this.data=[],this._page=1,this._minPage=1,this._count=0,this._initialized=!0,[2,!0]):(n=void 0,d=!1,this.isStatic?(o=void 0,a=200,[3,10]):[3,4]);case 4:return this.isDiscounted?(o=1,a=10,[3,10]):[3,5];case 5:return this.isRecommended?(o=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,S.getInstance().customerStore.getLastViewedProducts()];case 8:return(c=e.sent())&&c.length?(n=c.map((function(t){return t.productId})),d=S.getInstance().customerStore.useLastViewedProductResponse,[3,10]):[2];case 9:return[2];case 10:return d?(p=S.getInstance().customerStore._savedLastViewedProductsResponse,[3,13]):[3,11];case 11:return[4,this.searchProducts(o||1,a||10,n)];case 12:p=e.sent(),e.label=13;case 13:return(u=p)&&this._fetchRequestTime===t?(h=[],!d&&this.isLastViewed&&S.getInstance().customerStore.setSavedLastViewedProductsResponse(u),this.isStatic||this.isLastViewed?(f=this.isStatic?this._productListPropValue.productIds:S.getInstance().customerStore._lastViewedProducts,h=(null==f?void 0:f.map((function(t){var e,r,s=null===(r=null===(e=u.data)||void 0===e?void 0:e.data)||void 0===r?void 0:r.find((function(e){return e.id===t.productId})),o=null==s?void 0:s.variants.find((function(e){return e.id===t.variantId}));if((null==o?void 0:o.isActive)&&E.hasStock(o)||(o=null==s?void 0:s.variants.find((function(t){return t.isActive&&E.hasStock(t)}))),s&&o)return new l(i(i({},s),{selectedVariantValues:o.variantValues}))})).filter((function(t){return!!t})))||[]):h=(null===(_=null===(g=u.data)||void 0===g?void 0:g.data)||void 0===_?void 0:_.map((function(t){var e=I.getSelectedVariant(t);return new l(i(i({},t),{selectedVariantValues:e.variantValues}))})))||[],this.applyFacets(null===(v=u.data)||void 0===v?void 0:v.facets),this.data=h,this._count=(null===(y=u.data)||void 0===y?void 0:y.count)||0,this._initialized=!0,this._page=o||1,this._minPage=this.page,this.setIsFilteredForProducts(),this.setIsStaticForProducts(),s||(this._infiniteScrollPage=null),this.handleListingEvent(),[2,!0]):[2];case 14:return m=e.sent(),console.log(m),[3,16];case 15:return t===this._fetchRequestTime&&(this._isLoading=!1),[7];case 16:return[2]}}))}))},this.getPrev=function(){return t(u,void 0,void 0,(function(){var t,r,s,o,a,n,d,c=this;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(r=e.sent())?(s=null===(n=null===(a=r.data)||void 0===a?void 0:a.data)||void 0===n?void 0:n.map((function(t){var e=c.getSelectedVariant(t);return new l(i(i({},t),{selectedVariantValues:e.variantValues}))})),this.data=(null==s?void 0:s.concat(this.data))||this.data,this._count=(null===(d=r.data)||void 0===d?void 0:d.count)||this._count,this._minPage=t,this.setIsFilteredForProducts(),this.setIsStaticForProducts(),[3,5]):[2];case 3:return o=e.sent(),console.log(o),[3,5];case 4:return this._isLoading=!1,[7];case 5:return[2]}}))}))},this.getNext=function(){return t(u,void 0,void 0,(function(){var t,r,s,o,a,n,d=this;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())?(r=null===(a=null===(o=t.data)||void 0===o?void 0:o.data)||void 0===a?void 0:a.map((function(t){var e=d.getSelectedVariant(t);return new l(i(i({},t),{selectedVariantValues:e.variantValues}))})),this.data=this.data.concat(r||[]),this._count=(null===(n=t.data)||void 0===n?void 0:n.count)||this._count,this._page=this.page+1,this.setIsFilteredForProducts(),this.setIsStaticForProducts(),[3,5]):[2];case 3:return s=e.sent(),console.log(s),[3,5];case 4:return this._isLoading=!1,[7];case 5:return[2]}}))}))},this.getPage=function(r){return t(u,void 0,void 0,(function(){var t,s,o,a,n,d,c=this;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(r,this.limit)];case 2:return(t=e.sent())?(s=null===(n=null===(a=t.data)||void 0===a?void 0:a.data)||void 0===n?void 0:n.map((function(t){var e=c.getSelectedVariant(t);return new l(i(i({},t),{selectedVariantValues:e.variantValues}))})),this.data=s||[],this._count=(null===(d=t.data)||void 0===d?void 0:d.count)||0,this._page=r,this._minPage=r,this.setIsFilteredForProducts(),this.setIsStaticForProducts(),[3,5]):[2];case 3:return o=e.sent(),console.log(o),[3,5];case 4:return this._isLoading=!1,[7];case 5:return[2]}}))}))},this.setVisibleInfiniteScrollPage=function(t){var e;u._infiniteScrollPage!==t&&(u._infiniteScrollPage=t,_.getIsEditor()||null===(e=u.router)||void 0===e||e.replace("".concat(location.pathname).concat(u.queryParams?"?"+u.queryParams:""),void 0,{shallow:!0}))},this.searchDebouncer=s((function(){u.applyFilters()}),500),this.searchAnalyticsDebouncer=s((function(){v.search(u._searchKeyword,u.data.length)}),1e3);var p=a,h=a;if(this.data=a.data?a.data.map((function(t){return new l(t)})):[],this._type=p.type||h._type||p.productListPropValue.productListType||h._productListPropValue.productListType||P.ALL,this._pageType=a.pageType,this._sort=a.sort||a.productListPropValue.initialSort||T.LAST_ADDED,this._limit=a.limit||p.productListPropValue.initialLimit||h._productListPropValue.initialLimit||20,this._page=a.page||1,this._minPage=a.minPage||null,this._count=a.count||0,this._searchKeyword=a.searchKeyword||"",this._productListPropValue=p.productListPropValue||h._productListPropValue,this._filterBrandId=p.filterBrandId||h._filterBrandId||null,this._filterCategoryId=p.filterCategoryId||h._filterCategoryId||null,this._relatedProductData=p.relatedProductData||h._relatedProductData||null,this._recommendedProductData=p.recommendedProductData||h._recommendedProductData||null,this._viewedTogetherProductData=p.viewedTogetherProductData||h._viewedTogetherProductData||null,this._excludedFields=p.excludedFields||h._excludedFields||null,this._disabledSortTypes=p.disabledSortTypes||h._disabledSortTypes||null,this._recommendFor=p.recommendFor||h._recommendFor,this.filters=a.filters?a.filters.map((function(t){return new c(t,u)})):null,this._filterCategories=a.filterCategories?a.filterCategories.map((function(t){return new d(t)})):null,this.pageSpecificData=p.pageSpecificData||h.pageSpecificData||null,this.router=n,r(this,{router:!1}),this.setPageSpecificSort(),this.setIsFilteredForProducts(),this.setIsStaticForProducts(),this.isBrowser())if(this.restoreInfiniteScrollPage(),location.search&&(this.isFilterable||this._type===P.SEARCH)){var f=this.getQueryParams();this.getInitial(f,this._page>1)}else this._page>1?this.getInitial(void 0,!0):this.isLastViewed?this.getInitial():this.handleListingEvent()}return Object.defineProperty(C.prototype,"sort",{get:function(){return this._sort},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"limit",{get:function(){return this._limit},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"pageType",{get:function(){return this._pageType},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"page",{get:function(){return this._page},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"minPage",{get:function(){return this._minPage||1},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"count",{get:function(){return this._count},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"pageCount",{get:function(){return Math.ceil(this._count/this._limit)},enumerable:!1,configurable:!0}),Object.defineProperty(C.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(C.prototype,"isInitialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"isFilterable",{get:function(){return this._type===P.ALL||this._type===P.CATEGORY},enumerable:!1,configurable:!0}),Object.defineProperty(C.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!==o.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(C.prototype,"isStatic",{get:function(){return this._type===P.STATIC},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"isDiscounted",{get:function(){return this._type===P.DISCOUNTED},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"isRecommended",{get:function(){return this._type===P.RECOMMENDED},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"isLastViewed",{get:function(){return this._type===P.LAST_VIEWED},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"isRelatedProducts",{get:function(){return this._type===P.RELATED_PRODUCTS},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"isRecommendedProducts",{get:function(){return this._type===P.RECOMMENDED_PRODUCTS},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"isViewedTogetherProducts",{get:function(){return this._type===P.VIEWED_TOGETHER},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"isSearch",{get:function(){return this._type===P.SEARCH},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"hasPrev",{get:function(){return!(this.isStatic||this.isDiscounted||this.isRecommended||!this._minPage)&&this._minPage>1},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"hasNext",{get:function(){return!(this.isStatic||this.isDiscounted||this.isRecommended)&&this.page*this.limit<this.count},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"isLoading",{get:function(){return this._isLoading},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"queryParams",{get:function(){var t,e,i,r,s=this,a={};if(null===(t=this.filters)||void 0===t||t.forEach((function(t){t.keyList.length&&(a[y(t.name)]=t.keyList)})),this._searchKeyword&&(a.s=this._searchKeyword),this._sort&&(a.o=j[this._sort]),this._infiniteScrollPage&&(a.page=this._infiniteScrollPage),this._pageType!==o.CATEGORY){var n=null===(e=this.filterCategories)||void 0===e?void 0:e.filter((function(t){return t.isSelected}));if(!!(null==n?void 0:n.length))a.c=null==n?void 0:n.map((function(t){return t.slug}));else if(this._filterCategoryId){var d=null===(r=null===(i=this.filterCategories)||void 0===i?void 0:i.find((function(t){return t.id===s._filterCategoryId})))||void 0===r?void 0:r.slug;d&&(a.c=d)}}return h.stringify(a,{arrayFormat:"comma",encode:!1})},enumerable:!1,configurable:!0}),Object.defineProperty(C.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(C.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(C.prototype,"isFeaturedSortEnabled",{get:function(){var t;return(null===(t=this.pageSpecificData)||void 0===t?void 0:t.orderType)===a.MANUALLY&&[P.ALL,P.CATEGORY].includes(this._type)},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"disabledSortTypes",{get:function(){return this._disabledSortTypes},enumerable:!1,configurable:!0}),C.prototype.setIsFilteredForProducts=function(){var t=this;this.data.forEach((function(e){return e.isFiltered=t.isFiltered||!1}))},C.prototype.setIsStaticForProducts=function(){var t=this;this.data.forEach((function(e){return e.isStatic=t.isStatic||!1}))},C.prototype.setPageSpecificSort=function(){var t;if((null===(t=this.pageSpecificData)||void 0===t?void 0:t.orderType)&&[P.ALL].includes(this._type))switch(this.pageSpecificData.orderType){case a.HIGHEST_DISCOUNT_RATIO:this._sort=T.DECRASING_DISCOUNT;break;case a.LOWEST_DISCOUNT_RATIO:this._sort=T.INCREASING_DISCOUNT;break;case a.HIGHEST_PRICE:this._sort=T.DECREASING_PRICE;break;case a.LOWEST_PRICE:this._sort=T.INCREASING_PRICE;break;case a.NEWEST:this._sort=T.LAST_ADDED;break;case a.OLDEST:this._sort=T.FIRST_ADDED;break;case a.MANUALLY:this._sort=T.FEATURED}},C.prototype.getSortParams=function(){var t,e;switch(this._sort){case T.INCREASING_PRICE:t=f.ASC,e=m.PRICE;break;case T.DECREASING_PRICE:t=f.DESC,e=m.PRICE;break;case T.FIRST_ADDED:t=f.ASC,e=m.CREATED_AT;break;case T.LAST_ADDED:t=f.DESC,e=m.CREATED_AT;break;case T.INCREASING_DISCOUNT:t=f.ASC,e=m.DISCOUNT_RATIO;break;case T.DECRASING_DISCOUNT:t=f.DESC,e=m.DISCOUNT_RATIO;break;case T.FEATURED:if(this.isSearch)return;t=f.ASC,e=m.MANUAL_SORT;break;case T.DEFAULT:t=void 0,e=void 0;break;case T.AVERAGE_RATING:t=f.DESC,e=m.AVERAGE_RATING;break;case T.REVIEW_COUNT:t=f.DESC,e=m.REVIEW_COUNT;break;case T.SALE_COUNT:t=f.DESC,e=m.SALE_COUNT;break;case T.A_Z:t=f.ASC,e=m.NAME;break;case T.Z_A:t=f.DESC,e=m.NAME}if(t&&e)return{direction:t,type:e}},C.prototype.searchProducts=function(i,r,s){var a,d,c;return t(this,void 0,void 0,(function(){var t,l,h,f,m;return e(this,(function(e){switch(e.label){case 0:return t=[],l=[],null===(a=this.filters)||void 0===a||a.forEach((function(e){e.valueList.length&&t.push(new u({id:e.id,type:e.type,displayType:e.displayType,valueList:e.valueList})),e.isFacetFilter&&l.push({id:e.id,type:e.type,displayType:e.displayType})})),h=null===(d=this._filterCategories)||void 0===d?void 0:d.filter((function(t){return t.isSelected})).map((function(t){return t.id})),f=this.getSortParams(),this.isRelatedProducts&&this._relatedProductData?[4,p.getSuggestedProducts({priceListId:_.getPriceListId(),salesChannelId:_.getSalesChannelId(),productId:this._relatedProductData.productId,brandIds:this._relatedProductData.brandIds,categoryIds:this._relatedProductData.categoryIds,locale:_.getCurrentLocale()})]:[3,2];case 1:case 3:case 5:case 7:return[2,e.sent()];case 2:return this.isRecommendedProducts&&this._recommendedProductData?[4,p.getSuggestedProducts({priceListId:_.getPriceListId(),salesChannelId:_.getSalesChannelId(),brandIds:this._recommendedProductData.brandIds,categoryIds:this._recommendedProductData.categoryIds,locale:_.getCurrentLocale()})]:[3,4];case 4:return this.isViewedTogetherProducts&&this._viewedTogetherProductData?[4,p.getSuggestedProducts({priceListId:_.getPriceListId(),salesChannelId:_.getSalesChannelId(),method:g.VIEWED_TOGETHER,productIds:this._viewedTogetherProductData.productIds,locale:_.getCurrentLocale()})]:[3,6];case 6:return m={input:{page:i,perPage:r,productIdList:this.isStatic?null===(c=this._productListPropValue.productIds)||void 0===c?void 0:c.map((function(t){return t.productId})):s,filterList:t,facetList:l,brandId:this._pageType===o.BRAND&&this._type!==P.SEARCH?this._filterBrandId:void 0,categoryIdList:h&&h.length?h:this._filterCategoryId?[this._filterCategoryId]:void 0,priceListId:_.getPriceListId(),salesChannelId:_.getSalesChannelId(),query:this._searchKeyword,order:f?[f]:[],showStockOption:_.getStockPreference()||n.SHOW_ALL}},[4,p.searchProducts(m,this._excludedFields)]}}))}))},C.prototype.getFilters=function(){var i,r,s,a,n;return t(this,void 0,void 0,(function(){var t,d,u=this;return e(this,(function(e){switch(e.label){case 0:return[4,p.getProductFilterData({categoryId:this._filterCategoryId?this._filterCategoryId:void 0,locale:_.getCurrentLocale()})];case 1:return t=e.sent(),this.filters=null===(i=null==t?void 0:t.data)||void 0===i?void 0:i.filters.map((function(t){return new c(t,u)})),null===(r=this.filters)||void 0===r||r.forEach((function(t){if(t.values){var e=I.getDisplayedValues(t);t.values=e.map((function(e){var i;return null===(i=t.values)||void 0===i?void 0:i.find((function(t){return t.id===e.id}))}))}})),this._filterCategories=null===(s=null==t?void 0:t.data)||void 0===s?void 0:s.categories,this._disabledSortTypes=null===(a=t.data)||void 0===a?void 0:a.disabledSortTypes,this.pageType!==o.CATEGORY&&this._filterCategoryId&&(d=null===(n=this._filterCategories)||void 0===n?void 0:n.find((function(t){return t.id===u._filterCategoryId})))&&(d.isSelected=!0),this.filters&&this.filters.sort((function(t,e){return t.order>e.order?1:-1})),[2]}}))}))},C.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||t.name===e||y(t.name)===y(e)}));s&&s.applyQueryParam(t)}));var r=null==t?void 0:t.get("s");r&&(this._searchKeyword=r);var s=null==t?void 0:t.get("o");if(s){var a=parseInt(s),n=Object.entries(j).find((function(t){return t[1]===a}));n&&(this._sort=n[0])}if(this._pageType!==o.CATEGORY){var d=null==t?void 0:t.get("c"),c=null==d?void 0:d.split(",");c&&c.length&&(null===(e=this.filterCategories)||void 0===e||e.forEach((function(t){t.isSelected=c.some((function(e){return e===t.slug}))})))}}catch(t){console.log(t)}},C.prototype.applyFacets=function(t){var e,i;null===(e=this.filters)||void 0===e||e.forEach((function(e){var i,r,s,o=null==t?void 0:t.find((function(t){return t.id===e.id}));o?null===(i=e.values)||void 0===i||i.forEach((function(t){var i=o.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})))},C.prototype.setQueryParams=function(){var t;!this.isBrowser()||this.isSearch||_.getIsEditor()||null===(t=this.router)||void 0===t||t.replace("".concat(location.pathname).concat(this.queryParams?"?"+this.queryParams:""),void 0,{shallow:!0})},C.prototype.clearFilters=function(){var t,e;null===(t=this.filters)||void 0===t||t.forEach((function(t){return t.clear()})),this._searchKeyword="",this._pageType!==o.CATEGORY&&(this._filterCategoryId=void 0),null===(e=this._filterCategories)||void 0===e||e.forEach((function(t){return t.isSelected=!1})),this.applyFilters()},C.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()&&this.setQueryParams(),[2]}}))}))},C.prototype.onFilterCategoryClick=function(i,r){var s,o;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:_.getIsEditor()||null===(o=S.getInstance().router)||void 0===o||o.push(i.href+(this.queryParams?"?"+this.queryParams:"")),t.label=3;case 3:return[2]}}))}))},C.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}},C.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)}},C.prototype.getQueryParams=function(){if(this.isBrowser())return new URLSearchParams(location.search)},C.prototype.isBrowser=function(){return"undefined"!=typeof window},C.prototype.waitForCustomerStoreInit=function(){return new Promise((function(t){var e=setInterval((function(){S.getInstance().customerStore.initialized&&(clearInterval(e),t(null))}),1e3)}))},C.prototype.handleListingEvent=function(){this.searchKeyword&&this.data.length?v.viewSearchResults(this._searchKeyword,this.data):this.data.length&&this._type===P.ALL&&v.viewListing(this.data)},C}();!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",t.VIEWED_TOGETHER="VIEWED_TOGETHER",t.RECOMMENDED_PRODUCTS="RECOMMENDED_PRODUCTS"}(P||(P={})),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",t.DEFAULT="DEFAULT",t.AVERAGE_RATING="AVERAGE_RATING",t.REVIEW_COUNT="REVIEW_COUNT",t.SALE_COUNT="SALE_COUNT",t.A_Z="A_Z",t.Z_A="Z_A"}(T||(T={})),function(t){t.AVERAGE_RATING="AVERAGE_RATING",t.CREATED_AT="CREATED_AT",t.DISCOUNT_RATIO="DISCOUNT_RATIO",t.MANUAL_SORT="MANUAL_SORT",t.NAME="NAME",t.PRICE="PRICE",t.REVIEW_COUNT="REVIEW_COUNT",t.SALE_COUNT="SALE_COUNT"}(A||(A={})),function(t){t.CATEGORY="CATEGORY",t.BRAND="BRAND"}(D||(D={}));var j=((C={})[T.INCREASING_PRICE]=1,C[T.DECREASING_PRICE]=2,C[T.LAST_ADDED]=3,C[T.FIRST_ADDED]=4,C[T.INCREASING_DISCOUNT]=5,C[T.DECRASING_DISCOUNT]=6,C[T.FEATURED]=7,C[T.DEFAULT]=8,C[T.AVERAGE_RATING]=9,C[T.REVIEW_COUNT]=10,C[T.SALE_COUNT]=11,C[T.A_Z]=12,C[T.Z_A]=13,C);export{b as IkasProductList,A as IkasProductListSortByTypeEnum,T as IkasProductListSortType,P as IkasProductListType,D as IkasRelatedProductsType};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "6.1.0-beta.22",
3
+ "version": "6.1.0-beta.23",
4
4
  "description": "Storefront functionality for ikas storefront themes.",
5
5
  "author": "ikas",
6
6
  "license": "ISC",
@@ -21,11 +21,11 @@
21
21
  "swiper": "11.0.6"
22
22
  },
23
23
  "devDependencies": {
24
- "@ikas/storefront-api": "^6.1.0-beta.22",
25
- "@ikas/storefront-config": "^6.1.0-beta.22",
26
- "@ikas/storefront-model-functions": "^6.1.0-beta.22",
27
- "@ikas/storefront-models": "^6.1.0-beta.22",
28
- "@ikas/storefront-providers": "^6.1.0-beta.22",
24
+ "@ikas/storefront-api": "^6.1.0-beta.23",
25
+ "@ikas/storefront-config": "^6.1.0-beta.23",
26
+ "@ikas/storefront-model-functions": "^6.1.0-beta.23",
27
+ "@ikas/storefront-models": "^6.1.0-beta.23",
28
+ "@ikas/storefront-providers": "^6.1.0-beta.23",
29
29
  "@ikas/localized-address": "1.0.0-beta.6",
30
30
  "@adyen/adyen-web": "^5.57.0",
31
31
  "@rollup/plugin-commonjs": "^22.0.0",
@@ -60,11 +60,11 @@
60
60
  },
61
61
  "peerDependencies": {
62
62
  "@ikas/localized-address": "1.0.0-beta.6",
63
- "@ikas/storefront-api": "^6.1.0-beta.22",
64
- "@ikas/storefront-config": "^6.1.0-beta.22",
65
- "@ikas/storefront-model-functions": "^6.1.0-beta.22",
66
- "@ikas/storefront-models": "^6.1.0-beta.22",
67
- "@ikas/storefront-providers": "^6.1.0-beta.22",
63
+ "@ikas/storefront-api": "^6.1.0-beta.23",
64
+ "@ikas/storefront-config": "^6.1.0-beta.23",
65
+ "@ikas/storefront-model-functions": "^6.1.0-beta.23",
66
+ "@ikas/storefront-models": "^6.1.0-beta.23",
67
+ "@ikas/storefront-providers": "^6.1.0-beta.23",
68
68
  "mobx": "^6.1.3",
69
69
  "mobx-react-lite": "^3.1.5",
70
70
  "next": "12.2.0",