@ikas/storefront-providers 4.0.0-alpha.85 → 4.0.0-alpha.9

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.
Files changed (170) hide show
  1. package/package.json +12 -13
  2. package/{build/index.d.ts → src/index.ts} +22 -20
  3. package/src/models/prop-value/attribute-list.ts +8 -0
  4. package/src/models/prop-value/attribute.ts +8 -0
  5. package/src/models/prop-value/blog-category-list.ts +9 -0
  6. package/src/models/prop-value/blog-category.ts +6 -0
  7. package/src/models/prop-value/blog-list.ts +13 -0
  8. package/src/models/prop-value/blog.ts +6 -0
  9. package/src/models/prop-value/brand-list.ts +11 -0
  10. package/src/models/prop-value/brand.ts +6 -0
  11. package/src/models/prop-value/category-list.ts +11 -0
  12. package/src/models/prop-value/category.ts +6 -0
  13. package/src/models/prop-value/link.ts +22 -0
  14. package/src/models/prop-value/product-list.ts +29 -0
  15. package/src/models/prop-value/product.ts +7 -0
  16. package/src/models/prop-value/raffle-list.ts +6 -0
  17. package/src/models/prop-value/raffle.ts +6 -0
  18. package/src/models/ui/blog-category-list/index.ts +19 -0
  19. package/src/models/ui/blog-category-list/init.ts +54 -0
  20. package/src/models/ui/blog-list/index.ts +21 -0
  21. package/src/models/ui/blog-list/init.ts +49 -0
  22. package/src/models/ui/brand-list/index.ts +25 -0
  23. package/src/models/ui/brand-list/init.ts +47 -0
  24. package/src/models/ui/category-list/index.ts +25 -0
  25. package/src/models/ui/category-list/init.ts +50 -0
  26. package/src/models/ui/component-renderer/index.ts +5 -0
  27. package/src/models/ui/customer-review-list/index.ts +12 -0
  28. package/src/models/ui/customer-review-list/init.ts +33 -0
  29. package/src/models/ui/customer-review-summary-list/index.ts +12 -0
  30. package/src/models/ui/customer-review-summary-list/init.ts +33 -0
  31. package/{build/models/ui/index.d.ts → src/models/ui/index.ts} +12 -12
  32. package/src/models/ui/navigation-link/index.ts +7 -0
  33. package/src/models/ui/product-attribute-detail/index.ts +7 -0
  34. package/src/models/ui/product-attribute-list/index.ts +7 -0
  35. package/src/models/ui/product-list/index.ts +80 -0
  36. package/src/models/ui/product-list/init.ts +407 -0
  37. package/src/models/ui/raffle-list/index.ts +17 -0
  38. package/src/models/ui/raffle-list/init.ts +44 -0
  39. package/src/providers/helpers/raffle.ts +69 -0
  40. package/src/providers/page-data-get.ts +708 -0
  41. package/src/providers/placeholders.ts +138 -0
  42. package/src/providers/prop-value/attribute-list.ts +75 -0
  43. package/src/providers/prop-value/attribute.ts +77 -0
  44. package/src/providers/prop-value/blog-category-list.ts +29 -0
  45. package/src/providers/prop-value/blog-category.ts +49 -0
  46. package/src/providers/prop-value/blog-list.ts +61 -0
  47. package/src/providers/prop-value/blog.ts +41 -0
  48. package/src/providers/prop-value/boolean.ts +14 -0
  49. package/src/providers/prop-value/brand-list.ts +30 -0
  50. package/src/providers/prop-value/brand.ts +46 -0
  51. package/src/providers/prop-value/category-list.ts +31 -0
  52. package/src/providers/prop-value/category.ts +45 -0
  53. package/src/providers/prop-value/color.ts +14 -0
  54. package/src/providers/prop-value/custom.ts +560 -0
  55. package/src/providers/prop-value/image-list.ts +16 -0
  56. package/src/providers/prop-value/image.ts +16 -0
  57. package/{build/providers/prop-value/index.d.ts → src/providers/prop-value/index.ts} +3 -3
  58. package/src/providers/prop-value/link.ts +259 -0
  59. package/src/providers/prop-value/product-detail.ts +92 -0
  60. package/src/providers/prop-value/product-list.ts +124 -0
  61. package/src/providers/prop-value/raffle-list.ts +20 -0
  62. package/src/providers/prop-value/raffle.ts +41 -0
  63. package/src/providers/prop-value/rich-text.ts +14 -0
  64. package/src/providers/prop-value/slider.ts +19 -0
  65. package/src/providers/prop-value/text.ts +14 -0
  66. package/src/providers/types.ts +88 -0
  67. package/build/ext/tslib/tslib.es6.js +0 -1
  68. package/build/index.js +0 -1
  69. package/build/models/prop-value/attribute-list.d.ts +0 -6
  70. package/build/models/prop-value/attribute.d.ts +0 -6
  71. package/build/models/prop-value/blog-category-list.d.ts +0 -6
  72. package/build/models/prop-value/blog-category.d.ts +0 -4
  73. package/build/models/prop-value/blog-list.d.ts +0 -8
  74. package/build/models/prop-value/blog.d.ts +0 -4
  75. package/build/models/prop-value/brand-list.d.ts +0 -8
  76. package/build/models/prop-value/brand.d.ts +0 -4
  77. package/build/models/prop-value/brand.js +0 -1
  78. package/build/models/prop-value/category-list.d.ts +0 -8
  79. package/build/models/prop-value/category.d.ts +0 -4
  80. package/build/models/prop-value/link.d.ts +0 -18
  81. package/build/models/prop-value/link.js +0 -1
  82. package/build/models/prop-value/product-list.d.ts +0 -17
  83. package/build/models/prop-value/product.d.ts +0 -5
  84. package/build/models/prop-value/raffle-list.d.ts +0 -4
  85. package/build/models/prop-value/raffle.d.ts +0 -4
  86. package/build/models/ui/blog-category-list/index.d.ts +0 -17
  87. package/build/models/ui/blog-category-list/index.js +0 -1
  88. package/build/models/ui/blog-category-list/init.d.ts +0 -2
  89. package/build/models/ui/blog-category-list/init.js +0 -1
  90. package/build/models/ui/blog-list/index.d.ts +0 -19
  91. package/build/models/ui/blog-list/index.js +0 -1
  92. package/build/models/ui/blog-list/init.d.ts +0 -2
  93. package/build/models/ui/blog-list/init.js +0 -1
  94. package/build/models/ui/brand-list/index.d.ts +0 -22
  95. package/build/models/ui/brand-list/index.js +0 -1
  96. package/build/models/ui/brand-list/init.d.ts +0 -2
  97. package/build/models/ui/brand-list/init.js +0 -1
  98. package/build/models/ui/category-list/index.d.ts +0 -22
  99. package/build/models/ui/category-list/index.js +0 -1
  100. package/build/models/ui/category-list/init.d.ts +0 -2
  101. package/build/models/ui/category-list/init.js +0 -1
  102. package/build/models/ui/component-renderer/index.d.ts +0 -6
  103. package/build/models/ui/customer-review-list/index.d.ts +0 -11
  104. package/build/models/ui/customer-review-list/init.d.ts +0 -2
  105. package/build/models/ui/customer-review-summary-list/index.d.ts +0 -11
  106. package/build/models/ui/customer-review-summary-list/init.d.ts +0 -2
  107. package/build/models/ui/navigation-link/index.d.ts +0 -7
  108. package/build/models/ui/product-attribute-detail/index.d.ts +0 -6
  109. package/build/models/ui/product-attribute-list/index.d.ts +0 -6
  110. package/build/models/ui/product-list/index.d.ts +0 -64
  111. package/build/models/ui/product-list/index.js +0 -1
  112. package/build/models/ui/product-list/init.d.ts +0 -2
  113. package/build/models/ui/product-list/init.js +0 -1
  114. package/build/models/ui/raffle-list/index.d.ts +0 -16
  115. package/build/models/ui/raffle-list/init.d.ts +0 -2
  116. package/build/models/ui/raffle-list/init.js +0 -1
  117. package/build/providers/helpers/raffle.d.ts +0 -3
  118. package/build/providers/helpers/raffle.js +0 -1
  119. package/build/providers/page-data-get.d.ts +0 -31
  120. package/build/providers/page-data-get.js +0 -1
  121. package/build/providers/placeholders.d.ts +0 -7
  122. package/build/providers/placeholders.js +0 -1
  123. package/build/providers/prop-value/attribute-list.d.ts +0 -8
  124. package/build/providers/prop-value/attribute-list.js +0 -1
  125. package/build/providers/prop-value/attribute.d.ts +0 -8
  126. package/build/providers/prop-value/attribute.js +0 -1
  127. package/build/providers/prop-value/blog-category-list.d.ts +0 -8
  128. package/build/providers/prop-value/blog-category-list.js +0 -1
  129. package/build/providers/prop-value/blog-category.d.ts +0 -8
  130. package/build/providers/prop-value/blog-category.js +0 -1
  131. package/build/providers/prop-value/blog-list.d.ts +0 -11
  132. package/build/providers/prop-value/blog-list.js +0 -1
  133. package/build/providers/prop-value/blog.d.ts +0 -8
  134. package/build/providers/prop-value/blog.js +0 -1
  135. package/build/providers/prop-value/boolean.d.ts +0 -6
  136. package/build/providers/prop-value/boolean.js +0 -1
  137. package/build/providers/prop-value/brand-list.d.ts +0 -8
  138. package/build/providers/prop-value/brand-list.js +0 -1
  139. package/build/providers/prop-value/brand.d.ts +0 -8
  140. package/build/providers/prop-value/brand.js +0 -1
  141. package/build/providers/prop-value/category-list.d.ts +0 -8
  142. package/build/providers/prop-value/category-list.js +0 -1
  143. package/build/providers/prop-value/category.d.ts +0 -8
  144. package/build/providers/prop-value/category.js +0 -1
  145. package/build/providers/prop-value/color.d.ts +0 -6
  146. package/build/providers/prop-value/color.js +0 -1
  147. package/build/providers/prop-value/custom.d.ts +0 -42
  148. package/build/providers/prop-value/custom.js +0 -1
  149. package/build/providers/prop-value/image-list.d.ts +0 -7
  150. package/build/providers/prop-value/image-list.js +0 -1
  151. package/build/providers/prop-value/image.d.ts +0 -7
  152. package/build/providers/prop-value/image.js +0 -1
  153. package/build/providers/prop-value/link.d.ts +0 -26
  154. package/build/providers/prop-value/link.js +0 -1
  155. package/build/providers/prop-value/product-detail.d.ts +0 -8
  156. package/build/providers/prop-value/product-detail.js +0 -1
  157. package/build/providers/prop-value/product-list.d.ts +0 -17
  158. package/build/providers/prop-value/product-list.js +0 -1
  159. package/build/providers/prop-value/raffle-list.d.ts +0 -5
  160. package/build/providers/prop-value/raffle-list.js +0 -1
  161. package/build/providers/prop-value/raffle.d.ts +0 -8
  162. package/build/providers/prop-value/raffle.js +0 -1
  163. package/build/providers/prop-value/rich-text.d.ts +0 -6
  164. package/build/providers/prop-value/rich-text.js +0 -1
  165. package/build/providers/prop-value/slider.d.ts +0 -7
  166. package/build/providers/prop-value/slider.js +0 -1
  167. package/build/providers/prop-value/text.d.ts +0 -6
  168. package/build/providers/prop-value/text.js +0 -1
  169. package/build/providers/types.d.ts +0 -66
  170. package/build/providers/types.js +0 -1
@@ -1,12 +1,12 @@
1
- export * from "./blog-category-list";
2
- export * from "./blog-list";
3
- export * from "./brand-list";
4
- export * from "./category-list";
5
- export * from "./component-renderer";
6
- export * from "./customer-review-list";
7
- export * from "./customer-review-summary-list";
8
- export * from "./navigation-link";
9
- export * from "./product-attribute-detail";
10
- export * from "./product-attribute-list";
11
- export * from "./product-list";
12
- export * from "./raffle-list";
1
+ export * from "./blog-category-list";
2
+ export * from "./blog-list";
3
+ export * from "./brand-list";
4
+ export * from "./category-list";
5
+ export * from "./component-renderer";
6
+ export * from "./customer-review-list";
7
+ export * from "./customer-review-summary-list";
8
+ export * from "./navigation-link";
9
+ export * from "./product-attribute-detail";
10
+ export * from "./product-attribute-list";
11
+ export * from "./product-list";
12
+ export * from "./raffle-list";
@@ -0,0 +1,7 @@
1
+ export type IkasNavigationLink = {
2
+ href: string;
3
+ label: string;
4
+ subLinks: IkasNavigationLink[];
5
+ isExternal?: boolean | null;
6
+ itemId?: string;
7
+ };
@@ -0,0 +1,7 @@
1
+ import { IkasProduct } from "@ikas/storefront-models";
2
+ import { IkasAttributePropValue } from "../../prop-value/attribute";
3
+
4
+ export type IkasProductAttributeDetail = {
5
+ productDetail: IkasProduct | null;
6
+ attributePropValue: IkasAttributePropValue;
7
+ };
@@ -0,0 +1,7 @@
1
+ import { IkasProduct } from "@ikas/storefront-models";
2
+ import { IkasAttributeListPropValue } from "../../prop-value/attribute-list";
3
+
4
+ export type IkasAttributeList = {
5
+ productDetail: IkasProduct | null;
6
+ attributeListPropValue: IkasAttributeListPropValue;
7
+ };
@@ -0,0 +1,80 @@
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 };
@@ -0,0 +1,407 @@
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
+ }
@@ -0,0 +1,17 @@
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
+ };
@@ -0,0 +1,44 @@
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
+ }
@@ -0,0 +1,69 @@
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
+ };