@ikas/storefront-providers 4.0.0-alpha.7 → 4.0.0-alpha.70
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/ext/tslib/tslib.es6.js +1 -0
- package/{src/index.ts → build/index.d.ts} +20 -22
- package/build/index.js +1 -0
- package/build/models/prop-value/attribute-list.d.ts +6 -0
- package/build/models/prop-value/attribute.d.ts +6 -0
- package/build/models/prop-value/blog-category-list.d.ts +6 -0
- package/build/models/prop-value/blog-category.d.ts +4 -0
- package/build/models/prop-value/blog-list.d.ts +8 -0
- package/build/models/prop-value/blog.d.ts +4 -0
- package/build/models/prop-value/brand-list.d.ts +8 -0
- package/build/models/prop-value/brand.d.ts +4 -0
- package/build/models/prop-value/brand.js +1 -0
- package/build/models/prop-value/category-list.d.ts +8 -0
- package/build/models/prop-value/category.d.ts +4 -0
- package/build/models/prop-value/link.d.ts +18 -0
- package/build/models/prop-value/link.js +1 -0
- package/build/models/prop-value/product-list.d.ts +17 -0
- package/build/models/prop-value/product.d.ts +5 -0
- package/build/models/prop-value/raffle-list.d.ts +4 -0
- package/build/models/prop-value/raffle.d.ts +4 -0
- package/build/models/ui/blog-category-list/index.d.ts +17 -0
- package/build/models/ui/blog-category-list/index.js +1 -0
- package/build/models/ui/blog-category-list/init.d.ts +2 -0
- package/build/models/ui/blog-category-list/init.js +1 -0
- package/build/models/ui/blog-list/index.d.ts +19 -0
- package/build/models/ui/blog-list/index.js +1 -0
- package/build/models/ui/blog-list/init.d.ts +2 -0
- package/build/models/ui/blog-list/init.js +1 -0
- package/build/models/ui/brand-list/index.d.ts +22 -0
- package/build/models/ui/brand-list/index.js +1 -0
- package/build/models/ui/brand-list/init.d.ts +2 -0
- package/build/models/ui/brand-list/init.js +1 -0
- package/build/models/ui/category-list/index.d.ts +22 -0
- package/build/models/ui/category-list/index.js +1 -0
- package/build/models/ui/category-list/init.d.ts +2 -0
- package/build/models/ui/category-list/init.js +1 -0
- package/build/models/ui/component-renderer/index.d.ts +6 -0
- package/build/models/ui/customer-review-list/index.d.ts +11 -0
- package/build/models/ui/customer-review-list/init.d.ts +2 -0
- package/build/models/ui/customer-review-summary-list/index.d.ts +11 -0
- package/build/models/ui/customer-review-summary-list/init.d.ts +2 -0
- package/{src/models/ui/index.ts → build/models/ui/index.d.ts} +12 -12
- package/build/models/ui/navigation-link/index.d.ts +7 -0
- package/build/models/ui/product-attribute-detail/index.d.ts +6 -0
- package/build/models/ui/product-attribute-list/index.d.ts +6 -0
- package/build/models/ui/product-list/index.d.ts +64 -0
- package/build/models/ui/product-list/index.js +1 -0
- package/build/models/ui/product-list/init.d.ts +2 -0
- package/build/models/ui/product-list/init.js +1 -0
- package/build/models/ui/raffle-list/index.d.ts +16 -0
- package/build/models/ui/raffle-list/init.d.ts +2 -0
- package/build/models/ui/raffle-list/init.js +1 -0
- package/build/providers/helpers/raffle.d.ts +2 -0
- package/build/providers/helpers/raffle.js +1 -0
- package/build/providers/page-data-get.d.ts +31 -0
- package/build/providers/page-data-get.js +1 -0
- package/build/providers/placeholders.d.ts +7 -0
- package/build/providers/placeholders.js +1 -0
- package/build/providers/prop-value/attribute-list.d.ts +8 -0
- package/build/providers/prop-value/attribute-list.js +1 -0
- package/build/providers/prop-value/attribute.d.ts +8 -0
- package/build/providers/prop-value/attribute.js +1 -0
- package/build/providers/prop-value/blog-category-list.d.ts +8 -0
- package/build/providers/prop-value/blog-category-list.js +1 -0
- package/build/providers/prop-value/blog-category.d.ts +8 -0
- package/build/providers/prop-value/blog-category.js +1 -0
- package/build/providers/prop-value/blog-list.d.ts +11 -0
- package/build/providers/prop-value/blog-list.js +1 -0
- package/build/providers/prop-value/blog.d.ts +8 -0
- package/build/providers/prop-value/blog.js +1 -0
- package/build/providers/prop-value/boolean.d.ts +6 -0
- package/build/providers/prop-value/boolean.js +1 -0
- package/build/providers/prop-value/brand-list.d.ts +8 -0
- package/build/providers/prop-value/brand-list.js +1 -0
- package/build/providers/prop-value/brand.d.ts +8 -0
- package/build/providers/prop-value/brand.js +1 -0
- package/build/providers/prop-value/category-list.d.ts +8 -0
- package/build/providers/prop-value/category-list.js +1 -0
- package/build/providers/prop-value/category.d.ts +8 -0
- package/build/providers/prop-value/category.js +1 -0
- package/build/providers/prop-value/color.d.ts +6 -0
- package/build/providers/prop-value/color.js +1 -0
- package/build/providers/prop-value/custom.d.ts +42 -0
- package/build/providers/prop-value/custom.js +1 -0
- package/build/providers/prop-value/image-list.d.ts +7 -0
- package/build/providers/prop-value/image-list.js +1 -0
- package/build/providers/prop-value/image.d.ts +7 -0
- package/build/providers/prop-value/image.js +1 -0
- package/{src/providers/prop-value/index.ts → build/providers/prop-value/index.d.ts} +3 -3
- package/build/providers/prop-value/link.d.ts +26 -0
- package/build/providers/prop-value/link.js +1 -0
- package/build/providers/prop-value/product-detail.d.ts +8 -0
- package/build/providers/prop-value/product-detail.js +1 -0
- package/build/providers/prop-value/product-list.d.ts +17 -0
- package/build/providers/prop-value/product-list.js +1 -0
- package/build/providers/prop-value/raffle-list.d.ts +5 -0
- package/build/providers/prop-value/raffle-list.js +1 -0
- package/build/providers/prop-value/raffle.d.ts +8 -0
- package/build/providers/prop-value/raffle.js +1 -0
- package/build/providers/prop-value/rich-text.d.ts +6 -0
- package/build/providers/prop-value/rich-text.js +1 -0
- package/build/providers/prop-value/slider.d.ts +7 -0
- package/build/providers/prop-value/slider.js +1 -0
- package/build/providers/prop-value/text.d.ts +6 -0
- package/build/providers/prop-value/text.js +1 -0
- package/build/providers/types.d.ts +66 -0
- package/build/providers/types.js +1 -0
- package/package.json +13 -12
- package/src/models/prop-value/attribute-list.ts +0 -8
- package/src/models/prop-value/attribute.ts +0 -8
- package/src/models/prop-value/blog-category-list.ts +0 -9
- package/src/models/prop-value/blog-category.ts +0 -6
- package/src/models/prop-value/blog-list.ts +0 -13
- package/src/models/prop-value/blog.ts +0 -6
- package/src/models/prop-value/brand-list.ts +0 -11
- package/src/models/prop-value/brand.ts +0 -6
- package/src/models/prop-value/category-list.ts +0 -11
- package/src/models/prop-value/category.ts +0 -6
- package/src/models/prop-value/link.ts +0 -22
- package/src/models/prop-value/product-list.ts +0 -29
- package/src/models/prop-value/product.ts +0 -7
- package/src/models/prop-value/raffle-list.ts +0 -6
- package/src/models/prop-value/raffle.ts +0 -6
- package/src/models/ui/blog-category-list/index.ts +0 -19
- package/src/models/ui/blog-category-list/init.ts +0 -54
- package/src/models/ui/blog-list/index.ts +0 -21
- package/src/models/ui/blog-list/init.ts +0 -49
- package/src/models/ui/brand-list/index.ts +0 -25
- package/src/models/ui/brand-list/init.ts +0 -47
- package/src/models/ui/category-list/index.ts +0 -25
- package/src/models/ui/category-list/init.ts +0 -50
- package/src/models/ui/component-renderer/index.ts +0 -5
- package/src/models/ui/customer-review-list/index.ts +0 -12
- package/src/models/ui/customer-review-list/init.ts +0 -33
- package/src/models/ui/customer-review-summary-list/index.ts +0 -12
- package/src/models/ui/customer-review-summary-list/init.ts +0 -33
- package/src/models/ui/navigation-link/index.ts +0 -7
- package/src/models/ui/product-attribute-detail/index.ts +0 -7
- package/src/models/ui/product-attribute-list/index.ts +0 -7
- package/src/models/ui/product-list/index.ts +0 -80
- package/src/models/ui/product-list/init.ts +0 -407
- package/src/models/ui/raffle-list/index.ts +0 -17
- package/src/models/ui/raffle-list/init.ts +0 -44
- package/src/providers/helpers/raffle.ts +0 -69
- package/src/providers/page-data-get.ts +0 -708
- package/src/providers/placeholders.ts +0 -138
- package/src/providers/prop-value/attribute-list.ts +0 -75
- package/src/providers/prop-value/attribute.ts +0 -77
- package/src/providers/prop-value/blog-category-list.ts +0 -29
- package/src/providers/prop-value/blog-category.ts +0 -49
- package/src/providers/prop-value/blog-list.ts +0 -61
- package/src/providers/prop-value/blog.ts +0 -41
- package/src/providers/prop-value/boolean.ts +0 -14
- package/src/providers/prop-value/brand-list.ts +0 -30
- package/src/providers/prop-value/brand.ts +0 -46
- package/src/providers/prop-value/category-list.ts +0 -31
- package/src/providers/prop-value/category.ts +0 -45
- package/src/providers/prop-value/color.ts +0 -14
- package/src/providers/prop-value/custom.ts +0 -560
- package/src/providers/prop-value/image-list.ts +0 -16
- package/src/providers/prop-value/image.ts +0 -16
- package/src/providers/prop-value/link.ts +0 -259
- package/src/providers/prop-value/product-detail.ts +0 -92
- package/src/providers/prop-value/product-list.ts +0 -124
- package/src/providers/prop-value/raffle-list.ts +0 -20
- package/src/providers/prop-value/raffle.ts +0 -41
- package/src/providers/prop-value/rich-text.ts +0 -14
- package/src/providers/prop-value/slider.ts +0 -19
- package/src/providers/prop-value/text.ts +0 -14
- package/src/providers/types.ts +0 -88
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IkasBrand,
|
|
3
|
-
IkasCategory,
|
|
4
|
-
IkasFilterCategory,
|
|
5
|
-
IkasProduct,
|
|
6
|
-
IkasProductFilter,
|
|
7
|
-
IkasThemeJsonPageType,
|
|
8
|
-
} from "@ikas/storefront-models";
|
|
9
|
-
import { IkasRelatedProductProps } from "../../../providers/prop-value/product-list";
|
|
10
|
-
import { IkasProductListPropValue } from "../../prop-value/product-list";
|
|
11
|
-
|
|
12
|
-
export type IkasProductList = {
|
|
13
|
-
data: IkasProduct[];
|
|
14
|
-
filters: IkasProductFilter[] | null;
|
|
15
|
-
filterCategories?: IkasFilterCategory[] | null;
|
|
16
|
-
type: IkasProductListType;
|
|
17
|
-
pageType: IkasThemeJsonPageType;
|
|
18
|
-
sort: IkasProductListSortType;
|
|
19
|
-
limit: number;
|
|
20
|
-
page: number;
|
|
21
|
-
infiniteScrollPage: number | null;
|
|
22
|
-
count: number;
|
|
23
|
-
searchKeyword?: string;
|
|
24
|
-
initialized?: boolean;
|
|
25
|
-
minPage?: number | null;
|
|
26
|
-
productListPropValue: IkasProductListPropValue;
|
|
27
|
-
|
|
28
|
-
filterBrandId?: string | null;
|
|
29
|
-
filterCategoryId?: string | null;
|
|
30
|
-
relatedProductData?: IkasRelatedProductProps | null;
|
|
31
|
-
pageSpecificData: IkasCategory | IkasBrand | null;
|
|
32
|
-
|
|
33
|
-
recommendFor?: string | null; // productId
|
|
34
|
-
isLoading?: boolean;
|
|
35
|
-
fetchRequestTime?: number;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export enum IkasProductListType {
|
|
39
|
-
ALL = "ALL",
|
|
40
|
-
STATIC = "STATIC",
|
|
41
|
-
DISCOUNTED = "DISCOUNTED",
|
|
42
|
-
RECOMMENDED = "RECOMMENDED",
|
|
43
|
-
CATEGORY = "CATEGORY",
|
|
44
|
-
SEARCH = "SEARCH",
|
|
45
|
-
LAST_VIEWED = "LAST_VIEWED",
|
|
46
|
-
RELATED_PRODUCTS = "RELATED_PRODUCTS",
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export enum IkasProductListSortType {
|
|
50
|
-
INCREASING_PRICE = "INCREASING_PRICE",
|
|
51
|
-
DECREASING_PRICE = "DECREASING_PRICE",
|
|
52
|
-
LAST_ADDED = "LAST_ADDED",
|
|
53
|
-
FIRST_ADDED = "FIRST_ADDED",
|
|
54
|
-
INCREASING_DISCOUNT = "INCREASING_DISCOUNT",
|
|
55
|
-
DECRASING_DISCOUNT = "DECRASING_DISCOUNT",
|
|
56
|
-
FEATURED = "FEATURED",
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export enum IkasRelatedProductsType {
|
|
60
|
-
CATEGORY = "CATEGORY",
|
|
61
|
-
BRAND = "BRAND",
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export enum IkasProductSearchShowStockOption {
|
|
65
|
-
HIDE_OUT_OF_STOCK = "HIDE_OUT_OF_STOCK",
|
|
66
|
-
SHOW_ALL = "SHOW_ALL",
|
|
67
|
-
SHOW_OUT_OF_STOCK_AT_END = "SHOW_OUT_OF_STOCK_AT_END",
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export type Facet = {
|
|
71
|
-
id: string;
|
|
72
|
-
values: FacetValue[];
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export type FacetValue = {
|
|
76
|
-
id: string;
|
|
77
|
-
count: number;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export type { IkasRelatedProductProps };
|
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
import { IkasCategoryProductsOrderType } from "@ikas/storefront-models";
|
|
2
|
-
import {
|
|
3
|
-
IkasProduct,
|
|
4
|
-
IkasProductFacetInput,
|
|
5
|
-
IkasProductFilterValue,
|
|
6
|
-
IkasThemeJsonPageType,
|
|
7
|
-
} from "@ikas/storefront-models";
|
|
8
|
-
import _debounce from "lodash/debounce";
|
|
9
|
-
import {
|
|
10
|
-
IkasProductList,
|
|
11
|
-
IkasProductListSortType,
|
|
12
|
-
IkasProductListType,
|
|
13
|
-
} from "../product-list";
|
|
14
|
-
import { IkasProductFilterFunctions } from "@ikas/storefront-model-functions";
|
|
15
|
-
import {
|
|
16
|
-
SearchInputOrderByInput,
|
|
17
|
-
SortByDirectionEnum,
|
|
18
|
-
SortByTypeEnum,
|
|
19
|
-
} from "@ikas/storefront-api";
|
|
20
|
-
import {
|
|
21
|
-
getProductFilterData,
|
|
22
|
-
getRelatedProducts,
|
|
23
|
-
searchProducts,
|
|
24
|
-
} from "@ikas/storefront-api";
|
|
25
|
-
import { IkasStorefrontConfig } from "@ikas/storefront-config";
|
|
26
|
-
import { Facet, IkasProductSearchShowStockOption } from "..";
|
|
27
|
-
|
|
28
|
-
export async function getInitial(
|
|
29
|
-
list: IkasProductList,
|
|
30
|
-
isInfiteScrollReturn?: boolean
|
|
31
|
-
) {
|
|
32
|
-
setPageSpecificSort(list);
|
|
33
|
-
list.isLoading = true;
|
|
34
|
-
|
|
35
|
-
const fetchRequestTime = Date.now();
|
|
36
|
-
list.fetchRequestTime = fetchRequestTime;
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
let page: number | undefined = isInfiteScrollReturn ? list.page : 1;
|
|
40
|
-
let limit: number | undefined = list.limit;
|
|
41
|
-
|
|
42
|
-
if (isFilterable(list) && !list.filters) {
|
|
43
|
-
await getFilters(list);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (isSearch(list)) {
|
|
47
|
-
list.data = [];
|
|
48
|
-
list.page = 1;
|
|
49
|
-
list.minPage = 1;
|
|
50
|
-
list.count = 0;
|
|
51
|
-
list.initialized = true;
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
let productIdList: string[] | undefined;
|
|
56
|
-
|
|
57
|
-
if (isStatic(list)) {
|
|
58
|
-
page = undefined;
|
|
59
|
-
limit = 200;
|
|
60
|
-
} else if (isDiscounted(list)) {
|
|
61
|
-
page = 1;
|
|
62
|
-
limit = 10;
|
|
63
|
-
} else if (isRecommended(list)) {
|
|
64
|
-
page = 1;
|
|
65
|
-
limit = 10;
|
|
66
|
-
} else if (isLastViewed(list)) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const response = await _searchProducts(
|
|
71
|
-
list,
|
|
72
|
-
page || 1,
|
|
73
|
-
limit || 10,
|
|
74
|
-
productIdList
|
|
75
|
-
);
|
|
76
|
-
if (!response || list.fetchRequestTime !== fetchRequestTime) return;
|
|
77
|
-
|
|
78
|
-
let data: IkasProduct[] = [];
|
|
79
|
-
|
|
80
|
-
if (isLastViewed(list)) return;
|
|
81
|
-
|
|
82
|
-
if (isStatic(list)) {
|
|
83
|
-
const idList = list.productListPropValue.productIds || [];
|
|
84
|
-
|
|
85
|
-
data =
|
|
86
|
-
(idList
|
|
87
|
-
?.map((pID) => {
|
|
88
|
-
const product = response.data?.data?.find(
|
|
89
|
-
(p) => p.id === pID.productId
|
|
90
|
-
);
|
|
91
|
-
let variant = product?.variants.find((v) => v.id === pID.variantId);
|
|
92
|
-
|
|
93
|
-
if (!variant?.isActive) {
|
|
94
|
-
variant = product?.variants.find((v) => v.isActive);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (product && variant) {
|
|
98
|
-
const _product: IkasProduct = {
|
|
99
|
-
...product,
|
|
100
|
-
//@ts-ignore
|
|
101
|
-
selectedVariantValues: variant.variantValues,
|
|
102
|
-
};
|
|
103
|
-
return _product;
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
.filter((p) => !!p) as IkasProduct[]) || [];
|
|
107
|
-
} else {
|
|
108
|
-
data =
|
|
109
|
-
response.data?.data?.map((product) => {
|
|
110
|
-
const selectedVariant = product.variants.find((v) => v.isActive);
|
|
111
|
-
const _product: IkasProduct = {
|
|
112
|
-
...product,
|
|
113
|
-
//@ts-ignore
|
|
114
|
-
selectedVariantValues: (selectedVariant || product.variants[0])
|
|
115
|
-
.variantValues,
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
return _product;
|
|
119
|
-
}) || [];
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
applyFacets(list, response.data?.facets);
|
|
123
|
-
|
|
124
|
-
list.data = data;
|
|
125
|
-
list.count = response.data?.count || 0;
|
|
126
|
-
list.initialized = true;
|
|
127
|
-
list.page = page || 1;
|
|
128
|
-
list.minPage = list.page;
|
|
129
|
-
|
|
130
|
-
return true;
|
|
131
|
-
} catch (err) {
|
|
132
|
-
console.error(err);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function setPageSpecificSort(list: IkasProductList) {
|
|
137
|
-
if (
|
|
138
|
-
list.pageSpecificData?.orderType &&
|
|
139
|
-
[IkasProductListType.ALL, IkasProductListType.CATEGORY].includes(list.type)
|
|
140
|
-
) {
|
|
141
|
-
switch (list.pageSpecificData.orderType) {
|
|
142
|
-
case IkasCategoryProductsOrderType.HIGHEST_DISCOUNT_RATIO:
|
|
143
|
-
list.sort = IkasProductListSortType.DECRASING_DISCOUNT;
|
|
144
|
-
break;
|
|
145
|
-
|
|
146
|
-
case IkasCategoryProductsOrderType.LOWEST_DISCOUNT_RATIO:
|
|
147
|
-
list.sort = IkasProductListSortType.INCREASING_DISCOUNT;
|
|
148
|
-
break;
|
|
149
|
-
|
|
150
|
-
case IkasCategoryProductsOrderType.HIGHEST_PRICE:
|
|
151
|
-
list.sort = IkasProductListSortType.DECREASING_PRICE;
|
|
152
|
-
break;
|
|
153
|
-
|
|
154
|
-
case IkasCategoryProductsOrderType.LOWEST_PRICE:
|
|
155
|
-
list.sort = IkasProductListSortType.INCREASING_PRICE;
|
|
156
|
-
break;
|
|
157
|
-
|
|
158
|
-
case IkasCategoryProductsOrderType.NEWEST:
|
|
159
|
-
list.sort = IkasProductListSortType.LAST_ADDED;
|
|
160
|
-
break;
|
|
161
|
-
|
|
162
|
-
case IkasCategoryProductsOrderType.OLDEST:
|
|
163
|
-
list.sort = IkasProductListSortType.FIRST_ADDED;
|
|
164
|
-
break;
|
|
165
|
-
|
|
166
|
-
case IkasCategoryProductsOrderType.MANUALLY:
|
|
167
|
-
list.sort = IkasProductListSortType.FEATURED;
|
|
168
|
-
break;
|
|
169
|
-
|
|
170
|
-
default:
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function isFilterable(list: IkasProductList) {
|
|
177
|
-
return (
|
|
178
|
-
list.type === IkasProductListType.ALL ||
|
|
179
|
-
list.type === IkasProductListType.CATEGORY
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function isStatic(list: IkasProductList) {
|
|
184
|
-
return list.type === IkasProductListType.STATIC;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function isDiscounted(list: IkasProductList) {
|
|
188
|
-
return list.type === IkasProductListType.DISCOUNTED;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function isRecommended(list: IkasProductList) {
|
|
192
|
-
return list.type === IkasProductListType.RECOMMENDED;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function isLastViewed(list: IkasProductList) {
|
|
196
|
-
return list.type === IkasProductListType.LAST_VIEWED;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function isRelatedProducts(list: IkasProductList) {
|
|
200
|
-
return list.type === IkasProductListType.RELATED_PRODUCTS;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function isSearch(list: IkasProductList) {
|
|
204
|
-
return list.type === IkasProductListType.SEARCH;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function getSortParams(
|
|
208
|
-
list: IkasProductList
|
|
209
|
-
): SearchInputOrderByInput | undefined {
|
|
210
|
-
let direction: SortByDirectionEnum | undefined = SortByDirectionEnum.DESC;
|
|
211
|
-
let type: SortByTypeEnum = SortByTypeEnum.CREATED_AT;
|
|
212
|
-
|
|
213
|
-
switch (list.sort) {
|
|
214
|
-
case IkasProductListSortType.INCREASING_PRICE:
|
|
215
|
-
direction = SortByDirectionEnum.ASC;
|
|
216
|
-
type = SortByTypeEnum.PRICE;
|
|
217
|
-
break;
|
|
218
|
-
|
|
219
|
-
case IkasProductListSortType.DECREASING_PRICE:
|
|
220
|
-
direction = SortByDirectionEnum.DESC;
|
|
221
|
-
type = SortByTypeEnum.PRICE;
|
|
222
|
-
break;
|
|
223
|
-
|
|
224
|
-
case IkasProductListSortType.FIRST_ADDED:
|
|
225
|
-
direction = SortByDirectionEnum.ASC;
|
|
226
|
-
type = SortByTypeEnum.CREATED_AT;
|
|
227
|
-
break;
|
|
228
|
-
|
|
229
|
-
case IkasProductListSortType.LAST_ADDED:
|
|
230
|
-
direction = SortByDirectionEnum.DESC;
|
|
231
|
-
type = SortByTypeEnum.CREATED_AT;
|
|
232
|
-
break;
|
|
233
|
-
|
|
234
|
-
case IkasProductListSortType.INCREASING_DISCOUNT:
|
|
235
|
-
direction = SortByDirectionEnum.ASC;
|
|
236
|
-
type = SortByTypeEnum.DISCOUNT_RATIO;
|
|
237
|
-
break;
|
|
238
|
-
|
|
239
|
-
case IkasProductListSortType.DECRASING_DISCOUNT:
|
|
240
|
-
direction = SortByDirectionEnum.DESC;
|
|
241
|
-
type = SortByTypeEnum.DISCOUNT_RATIO;
|
|
242
|
-
break;
|
|
243
|
-
|
|
244
|
-
case IkasProductListSortType.FEATURED:
|
|
245
|
-
if (!isSearch(list)) {
|
|
246
|
-
direction = SortByDirectionEnum.ASC;
|
|
247
|
-
type = SortByTypeEnum.MANUAL_SORT;
|
|
248
|
-
} else {
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
break;
|
|
252
|
-
|
|
253
|
-
default:
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return {
|
|
258
|
-
direction,
|
|
259
|
-
type,
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
async function _searchProducts(
|
|
264
|
-
list: IkasProductList,
|
|
265
|
-
page: number,
|
|
266
|
-
limit: number,
|
|
267
|
-
productIdList?: string[]
|
|
268
|
-
) {
|
|
269
|
-
const filterList: IkasProductFilterValue[] = [];
|
|
270
|
-
const facetList: IkasProductFacetInput[] = [];
|
|
271
|
-
const { getValueList } = IkasProductFilterFunctions;
|
|
272
|
-
|
|
273
|
-
list.filters?.forEach((filter) => {
|
|
274
|
-
const valueList = getValueList(filter);
|
|
275
|
-
if (valueList.length) {
|
|
276
|
-
filterList.push({
|
|
277
|
-
id: filter.id,
|
|
278
|
-
type: filter.type,
|
|
279
|
-
displayType: filter.displayType,
|
|
280
|
-
valueList: valueList,
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (filter.isFacetFilter) {
|
|
285
|
-
facetList.push({
|
|
286
|
-
id: filter.id,
|
|
287
|
-
type: filter.type,
|
|
288
|
-
displayType: filter.displayType,
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
const selectedCategoryIds = list.filterCategories
|
|
294
|
-
?.filter((fc) => fc.isSelected)
|
|
295
|
-
.map((fc) => fc.id);
|
|
296
|
-
|
|
297
|
-
const sortParams = getSortParams(list);
|
|
298
|
-
|
|
299
|
-
if (isRelatedProducts(list)) {
|
|
300
|
-
if (list.relatedProductData) {
|
|
301
|
-
return await getRelatedProducts({
|
|
302
|
-
priceListId: IkasStorefrontConfig.getPriceListId(),
|
|
303
|
-
salesChannelId: IkasStorefrontConfig.getSalesChannelId(),
|
|
304
|
-
productId: list.relatedProductData.productId,
|
|
305
|
-
brandIds: list.relatedProductData.brandIds,
|
|
306
|
-
categoryIds: list.relatedProductData.categoryIds,
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return await searchProducts({
|
|
312
|
-
input: {
|
|
313
|
-
page,
|
|
314
|
-
perPage: limit,
|
|
315
|
-
productIdList: isStatic(list)
|
|
316
|
-
? list.productListPropValue.productIds?.map((p) => p.productId)
|
|
317
|
-
: productIdList,
|
|
318
|
-
filterList: filterList as any,
|
|
319
|
-
facetList: facetList as any,
|
|
320
|
-
brandId:
|
|
321
|
-
list.pageType === IkasThemeJsonPageType.BRAND &&
|
|
322
|
-
list.type !== IkasProductListType.SEARCH
|
|
323
|
-
? list.filterBrandId
|
|
324
|
-
: undefined,
|
|
325
|
-
categoryIdList:
|
|
326
|
-
selectedCategoryIds && selectedCategoryIds.length
|
|
327
|
-
? selectedCategoryIds
|
|
328
|
-
: list.filterCategoryId
|
|
329
|
-
? [list.filterCategoryId]
|
|
330
|
-
: undefined,
|
|
331
|
-
priceListId: IkasStorefrontConfig.getPriceListId(),
|
|
332
|
-
salesChannelId: IkasStorefrontConfig.getSalesChannelId(),
|
|
333
|
-
query: list.searchKeyword,
|
|
334
|
-
order:
|
|
335
|
-
list.type === IkasProductListType.SEARCH
|
|
336
|
-
? null
|
|
337
|
-
: sortParams
|
|
338
|
-
? [sortParams]
|
|
339
|
-
: null,
|
|
340
|
-
showStockOption:
|
|
341
|
-
(IkasStorefrontConfig.getStockPreference() as any) ||
|
|
342
|
-
IkasProductSearchShowStockOption.SHOW_ALL,
|
|
343
|
-
},
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
async function getFilters(list: IkasProductList) {
|
|
348
|
-
const getFiltersResponse = await getProductFilterData({
|
|
349
|
-
categoryId: list.filterCategoryId ? list.filterCategoryId : undefined,
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
list.filters = getFiltersResponse?.data?.filters || null;
|
|
353
|
-
list.filterCategories = getFiltersResponse?.data?.categories || null;
|
|
354
|
-
|
|
355
|
-
if (
|
|
356
|
-
list.pageType !== IkasThemeJsonPageType.CATEGORY &&
|
|
357
|
-
list.filterCategoryId
|
|
358
|
-
) {
|
|
359
|
-
const filterCategory = list.filterCategories?.find(
|
|
360
|
-
(fc) => fc.id === list.filterCategoryId
|
|
361
|
-
);
|
|
362
|
-
if (filterCategory) filterCategory.isSelected = true;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
if (list.filters)
|
|
366
|
-
list.filters.sort((f1, f2) => (f1.order > f2.order ? 1 : -1));
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
function applyFacets(
|
|
370
|
-
list: IkasProductList,
|
|
371
|
-
facets: Facet[] | undefined | null
|
|
372
|
-
) {
|
|
373
|
-
const { isCustomValueFilter } = IkasProductFilterFunctions;
|
|
374
|
-
list.filters?.forEach((filter) => {
|
|
375
|
-
const facet = facets?.find((f) => f.id === filter.id);
|
|
376
|
-
|
|
377
|
-
if (facet) {
|
|
378
|
-
filter.values?.forEach((filterValue) => {
|
|
379
|
-
const facetValue = facet.values.find(
|
|
380
|
-
(facetValue) => facetValue.id === filterValue.id
|
|
381
|
-
);
|
|
382
|
-
if (facetValue) filterValue.resultCount = facetValue.count;
|
|
383
|
-
else if (isCustomValueFilter(filter)) filterValue.resultCount = null;
|
|
384
|
-
else filterValue.resultCount = 0;
|
|
385
|
-
});
|
|
386
|
-
} else if (isCustomValueFilter(filter)) {
|
|
387
|
-
filter.values?.forEach((v) => (v.resultCount = null));
|
|
388
|
-
} else {
|
|
389
|
-
filter.values?.forEach((v) => (v.resultCount = 0));
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
// Category facets
|
|
394
|
-
const categoryFacet = facets?.find((f) => f.id === "category");
|
|
395
|
-
if (categoryFacet) {
|
|
396
|
-
list.filterCategories?.forEach((filterCategory) => {
|
|
397
|
-
const facetValue = categoryFacet.values.find(
|
|
398
|
-
(fv) => fv.id === filterCategory.id
|
|
399
|
-
);
|
|
400
|
-
if (facetValue) {
|
|
401
|
-
filterCategory.resultCount = facetValue.count;
|
|
402
|
-
} else {
|
|
403
|
-
filterCategory.resultCount = 0;
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { IkasRaffle } from "@ikas/storefront-models";
|
|
2
|
-
|
|
3
|
-
export type IkasRaffleList = {
|
|
4
|
-
data: IkasRaffle[];
|
|
5
|
-
limit: number;
|
|
6
|
-
page: number;
|
|
7
|
-
count: number;
|
|
8
|
-
initialized?: boolean;
|
|
9
|
-
minPage?: number | null;
|
|
10
|
-
start?: number | null;
|
|
11
|
-
end?: number | null;
|
|
12
|
-
includeDeleted?: boolean | null;
|
|
13
|
-
name?: string | null;
|
|
14
|
-
search?: string | null;
|
|
15
|
-
id?: string | null;
|
|
16
|
-
isLoading?: boolean;
|
|
17
|
-
};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { listRaffle } from "@ikas/storefront-api";
|
|
2
|
-
import { IkasRaffleList } from ".";
|
|
3
|
-
import { populateRaffleProducts } from "../../../providers/helpers/raffle";
|
|
4
|
-
|
|
5
|
-
export async function getInitial(list: IkasRaffleList) {
|
|
6
|
-
if (list.isLoading) return;
|
|
7
|
-
list.isLoading = true;
|
|
8
|
-
|
|
9
|
-
try {
|
|
10
|
-
const response = await getRaffleList(list, list.page, list.limit);
|
|
11
|
-
|
|
12
|
-
list.data = response.data?.data || [];
|
|
13
|
-
list.count = response.data?.count || 0;
|
|
14
|
-
list.initialized = true;
|
|
15
|
-
list.minPage = list.page;
|
|
16
|
-
} catch (err) {
|
|
17
|
-
console.log(err);
|
|
18
|
-
} finally {
|
|
19
|
-
list.isLoading = false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async function getRaffleList(
|
|
24
|
-
list: IkasRaffleList,
|
|
25
|
-
page: number,
|
|
26
|
-
limit: number
|
|
27
|
-
) {
|
|
28
|
-
const response = await listRaffle({
|
|
29
|
-
start: list.start ? { eq: list.start } : undefined,
|
|
30
|
-
end: list.end ? { eq: list.end } : undefined,
|
|
31
|
-
includeDeleted: list.includeDeleted || false,
|
|
32
|
-
name: list.name ? { eq: list.name } : undefined,
|
|
33
|
-
id: list.id ? { eq: list.id } : undefined,
|
|
34
|
-
search: list.search || undefined,
|
|
35
|
-
pagination: {
|
|
36
|
-
limit,
|
|
37
|
-
page,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
await populateRaffleProducts(response.data?.data || []);
|
|
42
|
-
|
|
43
|
-
return response;
|
|
44
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { listProductOptionSet, searchProducts } from "@ikas/storefront-api";
|
|
2
|
-
import { IkasRaffle } from "@ikas/storefront-models";
|
|
3
|
-
|
|
4
|
-
export const populateRaffleProducts = async (raffles: IkasRaffle[]) => {
|
|
5
|
-
const productIds: string[] = [];
|
|
6
|
-
for (const raffle of raffles) {
|
|
7
|
-
raffle.variants?.forEach((v) => {
|
|
8
|
-
if (!productIds.find((id) => id === v.productId)) {
|
|
9
|
-
productIds.push(v.productId);
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const productSearchResponse = await searchProducts({
|
|
15
|
-
input: {
|
|
16
|
-
productIdList: productIds,
|
|
17
|
-
// priceListId: IkasStorefrontConfig.priceListId,
|
|
18
|
-
// salesChannelId: IkasStorefrontConfig.salesChannelId,
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
if (productSearchResponse.isSuccess) {
|
|
23
|
-
const productList = productSearchResponse.data?.data || [];
|
|
24
|
-
|
|
25
|
-
if (productList.length) {
|
|
26
|
-
const productOptionSetIds = productList
|
|
27
|
-
.map((p) => p.productOptionSetId)
|
|
28
|
-
.filter((id) => !!id) as string[];
|
|
29
|
-
|
|
30
|
-
const productOptionSetsResponse = await listProductOptionSet({
|
|
31
|
-
id: { in: productOptionSetIds },
|
|
32
|
-
});
|
|
33
|
-
const productOptionSets = productOptionSetsResponse.data;
|
|
34
|
-
|
|
35
|
-
raffles.forEach((raffle) => {
|
|
36
|
-
raffle.variants?.forEach((variant) => {
|
|
37
|
-
const product = productList.find(
|
|
38
|
-
(product) => variant.productId === product.id
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
if (product) {
|
|
42
|
-
//@ts-ignore
|
|
43
|
-
product.productOptionSet = productOptionSets?.find(
|
|
44
|
-
(pos) => pos.id === product.productOptionSetId
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const selectedVariant =
|
|
48
|
-
product.variants.find(
|
|
49
|
-
(v) => v.isActive && variant.variantId === v.id
|
|
50
|
-
) || product.variants[0];
|
|
51
|
-
|
|
52
|
-
const _raffleProduct = raffle.products.find(
|
|
53
|
-
(p) => p.id === product.id
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
if (!_raffleProduct) {
|
|
57
|
-
//@ts-ignore
|
|
58
|
-
product.selectedVariantValues = selectedVariant.variantValues;
|
|
59
|
-
product.variants = product.variants.filter((v) =>
|
|
60
|
-
raffle.variants?.find((_v) => _v.variantId === v.id)
|
|
61
|
-
);
|
|
62
|
-
raffle.products.push(product);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|