@ikas/storefront-providers 4.0.0-alpha.10
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/package.json +46 -0
- package/src/index.ts +22 -0
- package/src/models/prop-value/attribute-list.ts +8 -0
- package/src/models/prop-value/attribute.ts +8 -0
- package/src/models/prop-value/blog-category-list.ts +9 -0
- package/src/models/prop-value/blog-category.ts +6 -0
- package/src/models/prop-value/blog-list.ts +13 -0
- package/src/models/prop-value/blog.ts +6 -0
- package/src/models/prop-value/brand-list.ts +11 -0
- package/src/models/prop-value/brand.ts +6 -0
- package/src/models/prop-value/category-list.ts +11 -0
- package/src/models/prop-value/category.ts +6 -0
- package/src/models/prop-value/link.ts +22 -0
- package/src/models/prop-value/product-list.ts +29 -0
- package/src/models/prop-value/product.ts +7 -0
- package/src/models/prop-value/raffle-list.ts +6 -0
- package/src/models/prop-value/raffle.ts +6 -0
- package/src/models/ui/blog-category-list/index.ts +19 -0
- package/src/models/ui/blog-category-list/init.ts +54 -0
- package/src/models/ui/blog-list/index.ts +21 -0
- package/src/models/ui/blog-list/init.ts +49 -0
- package/src/models/ui/brand-list/index.ts +25 -0
- package/src/models/ui/brand-list/init.ts +47 -0
- package/src/models/ui/category-list/index.ts +25 -0
- package/src/models/ui/category-list/init.ts +50 -0
- package/src/models/ui/component-renderer/index.ts +5 -0
- package/src/models/ui/customer-review-list/index.ts +12 -0
- package/src/models/ui/customer-review-list/init.ts +33 -0
- package/src/models/ui/customer-review-summary-list/index.ts +12 -0
- package/src/models/ui/customer-review-summary-list/init.ts +33 -0
- package/src/models/ui/index.ts +12 -0
- package/src/models/ui/navigation-link/index.ts +7 -0
- package/src/models/ui/product-attribute-detail/index.ts +7 -0
- package/src/models/ui/product-attribute-list/index.ts +7 -0
- package/src/models/ui/product-list/index.ts +80 -0
- package/src/models/ui/product-list/init.ts +407 -0
- package/src/models/ui/raffle-list/index.ts +17 -0
- package/src/models/ui/raffle-list/init.ts +44 -0
- package/src/providers/helpers/raffle.ts +69 -0
- package/src/providers/page-data-get.ts +708 -0
- package/src/providers/placeholders.ts +138 -0
- package/src/providers/prop-value/attribute-list.ts +75 -0
- package/src/providers/prop-value/attribute.ts +77 -0
- package/src/providers/prop-value/blog-category-list.ts +29 -0
- package/src/providers/prop-value/blog-category.ts +49 -0
- package/src/providers/prop-value/blog-list.ts +61 -0
- package/src/providers/prop-value/blog.ts +41 -0
- package/src/providers/prop-value/boolean.ts +14 -0
- package/src/providers/prop-value/brand-list.ts +30 -0
- package/src/providers/prop-value/brand.ts +46 -0
- package/src/providers/prop-value/category-list.ts +31 -0
- package/src/providers/prop-value/category.ts +45 -0
- package/src/providers/prop-value/color.ts +14 -0
- package/src/providers/prop-value/custom.ts +560 -0
- package/src/providers/prop-value/image-list.ts +16 -0
- package/src/providers/prop-value/image.ts +16 -0
- package/src/providers/prop-value/index.ts +3 -0
- package/src/providers/prop-value/link.ts +259 -0
- package/src/providers/prop-value/product-detail.ts +92 -0
- package/src/providers/prop-value/product-list.ts +124 -0
- package/src/providers/prop-value/raffle-list.ts +20 -0
- package/src/providers/prop-value/raffle.ts +41 -0
- package/src/providers/prop-value/rich-text.ts +14 -0
- package/src/providers/prop-value/slider.ts +19 -0
- package/src/providers/prop-value/text.ts +14 -0
- package/src/providers/types.ts +88 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { IkasThemeJson, IkasThemeJsonPageType } from "@ikas/storefront-models";
|
|
2
|
+
import IkasPropValueProvider from ".";
|
|
3
|
+
import { IkasLinkPropValue, IkasLinkType } from "../../models/prop-value/link";
|
|
4
|
+
import { IkasNavigationLink } from "../../models/ui";
|
|
5
|
+
|
|
6
|
+
export type IkasLinkMetaDataType = "DEFAULT" | "BLOG" | "RAFFLE";
|
|
7
|
+
export type IkasLinkMetaDataTargetId = {
|
|
8
|
+
type: IkasLinkMetaDataType;
|
|
9
|
+
id: string;
|
|
10
|
+
navigationLink: IkasNavigationLink;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export class IkasLinkPropValueProvider
|
|
14
|
+
implements IkasPropValueProvider<IkasNavigationLink | IkasNavigationLink[]>
|
|
15
|
+
{
|
|
16
|
+
private linkPropValue: IkasLinkPropValue | IkasLinkPropValue[];
|
|
17
|
+
private theme: IkasThemeJson;
|
|
18
|
+
private linkMetaDataTargetIds: IkasLinkMetaDataTargetId[];
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
linkPropValue: IkasLinkPropValue | IkasLinkPropValue[],
|
|
22
|
+
theme: IkasThemeJson,
|
|
23
|
+
linkMetaDataTargetIds: IkasLinkMetaDataTargetId[]
|
|
24
|
+
) {
|
|
25
|
+
this.linkPropValue = linkPropValue;
|
|
26
|
+
this.theme = theme;
|
|
27
|
+
this.linkMetaDataTargetIds = linkMetaDataTargetIds;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private async getNavigationLink(
|
|
31
|
+
linkPropValue: IkasLinkPropValue
|
|
32
|
+
): Promise<IkasNavigationLink> {
|
|
33
|
+
let navigationLink: IkasNavigationLink | undefined;
|
|
34
|
+
|
|
35
|
+
if (linkPropValue.linkType === IkasLinkType.PAGE) {
|
|
36
|
+
// INDEX PAGE
|
|
37
|
+
if (linkPropValue.pageType === IkasThemeJsonPageType.INDEX) {
|
|
38
|
+
navigationLink = {
|
|
39
|
+
href: "/",
|
|
40
|
+
label: linkPropValue.label || "",
|
|
41
|
+
subLinks: [],
|
|
42
|
+
};
|
|
43
|
+
} else if (linkPropValue.pageType === IkasThemeJsonPageType.ACCOUNT) {
|
|
44
|
+
navigationLink = {
|
|
45
|
+
href: "/account",
|
|
46
|
+
label: linkPropValue.label || "",
|
|
47
|
+
subLinks: [],
|
|
48
|
+
};
|
|
49
|
+
} else if (linkPropValue.pageType === IkasThemeJsonPageType.ADDRESSES) {
|
|
50
|
+
navigationLink = {
|
|
51
|
+
href: "/account/addresses",
|
|
52
|
+
label: linkPropValue.label || "",
|
|
53
|
+
subLinks: [],
|
|
54
|
+
};
|
|
55
|
+
} else if (linkPropValue.pageType === IkasThemeJsonPageType.ORDERS) {
|
|
56
|
+
navigationLink = {
|
|
57
|
+
href: "/account/orders",
|
|
58
|
+
label: linkPropValue.label || "",
|
|
59
|
+
subLinks: [],
|
|
60
|
+
};
|
|
61
|
+
} else if (
|
|
62
|
+
linkPropValue.pageType === IkasThemeJsonPageType.FAVORITE_PRODUCTS
|
|
63
|
+
) {
|
|
64
|
+
navigationLink = {
|
|
65
|
+
href: "/account/favorite-products",
|
|
66
|
+
label: linkPropValue.label || "",
|
|
67
|
+
subLinks: [],
|
|
68
|
+
};
|
|
69
|
+
} else if (linkPropValue.pageType === IkasThemeJsonPageType.LOGIN) {
|
|
70
|
+
navigationLink = {
|
|
71
|
+
href: "/account/login",
|
|
72
|
+
label: linkPropValue.label || "",
|
|
73
|
+
subLinks: [],
|
|
74
|
+
};
|
|
75
|
+
} else if (linkPropValue.pageType === IkasThemeJsonPageType.REGISTER) {
|
|
76
|
+
navigationLink = {
|
|
77
|
+
href: "/account/register",
|
|
78
|
+
label: linkPropValue.label || "",
|
|
79
|
+
subLinks: [],
|
|
80
|
+
};
|
|
81
|
+
} else if (
|
|
82
|
+
linkPropValue.pageType === IkasThemeJsonPageType.FORGOT_PASSWORD
|
|
83
|
+
) {
|
|
84
|
+
navigationLink = {
|
|
85
|
+
href: "/account/forgot-password",
|
|
86
|
+
label: linkPropValue.label || "",
|
|
87
|
+
subLinks: [],
|
|
88
|
+
};
|
|
89
|
+
} else if (
|
|
90
|
+
linkPropValue.pageType === IkasThemeJsonPageType.RECOVER_PASSWORD
|
|
91
|
+
) {
|
|
92
|
+
navigationLink = {
|
|
93
|
+
href: "/account/recover-password",
|
|
94
|
+
label: linkPropValue.label || "",
|
|
95
|
+
subLinks: [],
|
|
96
|
+
};
|
|
97
|
+
} else if (linkPropValue.pageType === IkasThemeJsonPageType.BLOG_INDEX) {
|
|
98
|
+
navigationLink = {
|
|
99
|
+
href: "/blog",
|
|
100
|
+
label: linkPropValue.label || "",
|
|
101
|
+
subLinks: [],
|
|
102
|
+
};
|
|
103
|
+
} else if (linkPropValue.pageType === IkasThemeJsonPageType.CART) {
|
|
104
|
+
navigationLink = {
|
|
105
|
+
href: "/cart",
|
|
106
|
+
label: linkPropValue.label || "",
|
|
107
|
+
subLinks: [],
|
|
108
|
+
};
|
|
109
|
+
} else if (linkPropValue.pageType === IkasThemeJsonPageType.SEARCH) {
|
|
110
|
+
navigationLink = {
|
|
111
|
+
href: "/search",
|
|
112
|
+
label: linkPropValue.label || "",
|
|
113
|
+
subLinks: [],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
// CUSTOM PAGE
|
|
117
|
+
else if (linkPropValue.pageType === IkasThemeJsonPageType.CUSTOM) {
|
|
118
|
+
const themePage = this.theme.pages.find(
|
|
119
|
+
(p) => p.id === linkPropValue.pageId
|
|
120
|
+
);
|
|
121
|
+
if (themePage) {
|
|
122
|
+
navigationLink = {
|
|
123
|
+
href: "/pages/" + themePage.slug,
|
|
124
|
+
label: linkPropValue.label || "",
|
|
125
|
+
subLinks: [],
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// ITEM PAGES
|
|
130
|
+
else if (
|
|
131
|
+
[
|
|
132
|
+
IkasThemeJsonPageType.PRODUCT,
|
|
133
|
+
IkasThemeJsonPageType.BRAND,
|
|
134
|
+
IkasThemeJsonPageType.CATEGORY,
|
|
135
|
+
].includes(linkPropValue.pageType!)
|
|
136
|
+
) {
|
|
137
|
+
if (linkPropValue.itemId) {
|
|
138
|
+
navigationLink = {
|
|
139
|
+
href: "/",
|
|
140
|
+
label: linkPropValue.label || "",
|
|
141
|
+
subLinks: [],
|
|
142
|
+
};
|
|
143
|
+
this.linkMetaDataTargetIds.push({
|
|
144
|
+
type: "DEFAULT",
|
|
145
|
+
id: linkPropValue.itemId,
|
|
146
|
+
navigationLink,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// BLOG ITEM PAGES
|
|
151
|
+
else if (
|
|
152
|
+
[
|
|
153
|
+
IkasThemeJsonPageType.BLOG,
|
|
154
|
+
IkasThemeJsonPageType.BLOG_CATEGORY,
|
|
155
|
+
].includes(linkPropValue.pageType!)
|
|
156
|
+
) {
|
|
157
|
+
if (linkPropValue.itemId) {
|
|
158
|
+
navigationLink = {
|
|
159
|
+
href: "/blog/",
|
|
160
|
+
label: linkPropValue.label || "",
|
|
161
|
+
subLinks: [],
|
|
162
|
+
};
|
|
163
|
+
this.linkMetaDataTargetIds.push({
|
|
164
|
+
type: "BLOG",
|
|
165
|
+
id: linkPropValue.itemId,
|
|
166
|
+
navigationLink,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// RAFFLE ITEM PAGE
|
|
171
|
+
else if (linkPropValue.pageType === IkasThemeJsonPageType.RAFFLE_DETAIL) {
|
|
172
|
+
if (linkPropValue.itemId) {
|
|
173
|
+
navigationLink = {
|
|
174
|
+
href: "/raffle/",
|
|
175
|
+
label: linkPropValue.label || "",
|
|
176
|
+
subLinks: [],
|
|
177
|
+
};
|
|
178
|
+
this.linkMetaDataTargetIds.push({
|
|
179
|
+
type: "RAFFLE",
|
|
180
|
+
id: linkPropValue.itemId,
|
|
181
|
+
navigationLink,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// RAFFLE ITEM PAGE
|
|
186
|
+
// else if (linkPropValue.pageType === IkasThemeJsonPageType.RAFFLE_DETAIL) {
|
|
187
|
+
// if (linkPropValue.itemId) {
|
|
188
|
+
// navigationLink = new IkasNavigationLink(
|
|
189
|
+
// "/raffle/",
|
|
190
|
+
// linkPropValue.label || "",
|
|
191
|
+
// []
|
|
192
|
+
// );
|
|
193
|
+
// this.linkMetaDataTargetIds.push({
|
|
194
|
+
// type: "RAFFLE",
|
|
195
|
+
// id: linkPropValue.itemId,
|
|
196
|
+
// navigationLink,
|
|
197
|
+
// });
|
|
198
|
+
// }
|
|
199
|
+
// }
|
|
200
|
+
}
|
|
201
|
+
// EXTERNAL LINK
|
|
202
|
+
else if (linkPropValue.linkType === IkasLinkType.EXTERNAL) {
|
|
203
|
+
navigationLink = {
|
|
204
|
+
href: linkPropValue.externalLink || "",
|
|
205
|
+
label: linkPropValue.label || "",
|
|
206
|
+
subLinks: [],
|
|
207
|
+
isExternal: true,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (navigationLink) {
|
|
212
|
+
navigationLink.subLinks = await Promise.all(
|
|
213
|
+
linkPropValue.subLinks.map((sl) => this.getNavigationLink(sl))
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
// ADD HASH LINK
|
|
217
|
+
if (linkPropValue.pageComponentId && linkPropValue.pageId) {
|
|
218
|
+
const page = this.theme.pages.find(
|
|
219
|
+
(p) => p.id === linkPropValue.pageId
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const headerComponentId = this.theme.components.find(
|
|
223
|
+
(c) => c.isHeader
|
|
224
|
+
)?.id;
|
|
225
|
+
const footerComponentId = this.theme.components.find(
|
|
226
|
+
(c) => c.isFooter
|
|
227
|
+
)?.id;
|
|
228
|
+
|
|
229
|
+
const pageComponents =
|
|
230
|
+
page?.components.filter(
|
|
231
|
+
(pc) =>
|
|
232
|
+
pc.componentId !== headerComponentId &&
|
|
233
|
+
pc.componentId !== footerComponentId
|
|
234
|
+
) || [];
|
|
235
|
+
|
|
236
|
+
const componentIndex = pageComponents.findIndex(
|
|
237
|
+
(pc) => pc.id === linkPropValue.pageComponentId
|
|
238
|
+
);
|
|
239
|
+
if (componentIndex !== -1) {
|
|
240
|
+
navigationLink.href += "#" + componentIndex;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return navigationLink;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return { href: "", label: "", subLinks: [] } as IkasNavigationLink;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async getValue(): Promise<IkasNavigationLink | IkasNavigationLink[]> {
|
|
251
|
+
if (Array.isArray(this.linkPropValue)) {
|
|
252
|
+
return await Promise.all(
|
|
253
|
+
this.linkPropValue.map((lpv) => this.getNavigationLink(lpv))
|
|
254
|
+
);
|
|
255
|
+
} else {
|
|
256
|
+
return await this.getNavigationLink(this.linkPropValue);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { listProductOptionSet, searchProducts } from "@ikas/storefront-api";
|
|
2
|
+
import { IkasStorefrontConfig } from "@ikas/storefront-config";
|
|
3
|
+
import { IkasProductFunctions } from "@ikas/storefront-model-functions";
|
|
4
|
+
import IkasPropValueProvider from ".";
|
|
5
|
+
import { IkasProductPropValue } from "../../models/prop-value/product";
|
|
6
|
+
import { getPlaceholderProduct } from "../placeholders";
|
|
7
|
+
import {
|
|
8
|
+
IkasProductPropValueData,
|
|
9
|
+
IkasProductPropValueProduct,
|
|
10
|
+
} from "../types";
|
|
11
|
+
|
|
12
|
+
export class IkasProductPropValueProvider
|
|
13
|
+
implements IkasPropValueProvider<IkasProductPropValueData | null>
|
|
14
|
+
{
|
|
15
|
+
private productDetailPropValue: IkasProductPropValue;
|
|
16
|
+
|
|
17
|
+
constructor(prop: IkasProductPropValue) {
|
|
18
|
+
this.productDetailPropValue = prop;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async getValue(): Promise<IkasProductPropValueData | null> {
|
|
22
|
+
if (this.productDetailPropValue?.usePageData) {
|
|
23
|
+
return {
|
|
24
|
+
productDetailPropValue: this.productDetailPropValue,
|
|
25
|
+
productDetail: null,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (!this.productDetailPropValue.productId) return null;
|
|
29
|
+
|
|
30
|
+
const productSearchResponse = await searchProducts({
|
|
31
|
+
input: {
|
|
32
|
+
productIdList: [this.productDetailPropValue.productId],
|
|
33
|
+
priceListId: IkasStorefrontConfig.getPriceListId(),
|
|
34
|
+
salesChannelId: IkasStorefrontConfig.getSalesChannelId(),
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (productSearchResponse.isSuccess && productSearchResponse.data?.data) {
|
|
39
|
+
const productList: IkasProductPropValueProduct[] =
|
|
40
|
+
productSearchResponse.data.data;
|
|
41
|
+
|
|
42
|
+
if (productList.length) {
|
|
43
|
+
const product = productList[0];
|
|
44
|
+
|
|
45
|
+
// Set product option set if exists
|
|
46
|
+
if (product.productOptionSetId) {
|
|
47
|
+
const optionSetResponse = await listProductOptionSet({
|
|
48
|
+
id: { eq: product.productOptionSetId },
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (optionSetResponse.isSuccess && optionSetResponse.data?.length) {
|
|
52
|
+
product.productOptionSet = optionSetResponse.data[0];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const { hasVariant } = IkasProductFunctions;
|
|
57
|
+
|
|
58
|
+
if (product && hasVariant(product)) {
|
|
59
|
+
const variant = product.variants.find(
|
|
60
|
+
(v) => v.id === this.productDetailPropValue.variantId
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
if (variant) {
|
|
64
|
+
product.selectedVariantValues = variant?.variantValues;
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
productDetailPropValue: this.productDetailPropValue,
|
|
68
|
+
productDetail: product,
|
|
69
|
+
};
|
|
70
|
+
} else return null;
|
|
71
|
+
} else {
|
|
72
|
+
const selectedVariant = product.variants.find((v) => v.isActive);
|
|
73
|
+
product.selectedVariantValues = (
|
|
74
|
+
selectedVariant || product.variants[0]
|
|
75
|
+
).variantValues;
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
productDetailPropValue: this.productDetailPropValue,
|
|
79
|
+
productDetail: product,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
return {
|
|
84
|
+
productDetailPropValue: this.productDetailPropValue,
|
|
85
|
+
productDetail: getPlaceholderProduct(),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IkasBrand,
|
|
3
|
+
IkasCategory,
|
|
4
|
+
IkasThemeJsonPageType,
|
|
5
|
+
} from "@ikas/storefront-models";
|
|
6
|
+
import IkasPropValueProvider from ".";
|
|
7
|
+
import { IkasProductListPropValue } from "../../models/prop-value/product-list";
|
|
8
|
+
import {
|
|
9
|
+
IkasProductList,
|
|
10
|
+
IkasProductListSortType,
|
|
11
|
+
IkasProductListType,
|
|
12
|
+
IkasRelatedProductsType,
|
|
13
|
+
} from "../../models/ui";
|
|
14
|
+
import { getInitial } from "../../models/ui/product-list/init";
|
|
15
|
+
|
|
16
|
+
export type IkasRelatedProductProps = {
|
|
17
|
+
brandIds: string[] | null;
|
|
18
|
+
categoryIds: string[] | null;
|
|
19
|
+
productId: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export class IkasProductListPropValueProvider
|
|
23
|
+
implements IkasPropValueProvider<IkasProductList>
|
|
24
|
+
{
|
|
25
|
+
private pageType: IkasThemeJsonPageType;
|
|
26
|
+
private productListPropValue: IkasProductListPropValue;
|
|
27
|
+
private pageSpecificData?: any;
|
|
28
|
+
|
|
29
|
+
private relatedProductData?: IkasRelatedProductProps | null = null;
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
pageType: IkasThemeJsonPageType,
|
|
33
|
+
productListPropValue: IkasProductListPropValue,
|
|
34
|
+
pageSpecificData?: any
|
|
35
|
+
) {
|
|
36
|
+
this.pageType = pageType;
|
|
37
|
+
this.productListPropValue = productListPropValue;
|
|
38
|
+
this.pageSpecificData = pageSpecificData;
|
|
39
|
+
this.relatedProductData = null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async getValue(): Promise<IkasProductList> {
|
|
43
|
+
let filterBrandId: string | undefined;
|
|
44
|
+
let filterCategoryId: string | undefined;
|
|
45
|
+
|
|
46
|
+
if (this.productListPropValue.productListType === IkasProductListType.ALL) {
|
|
47
|
+
if (this.productListPropValue.usePageFilter) {
|
|
48
|
+
if (this.pageType === IkasThemeJsonPageType.CATEGORY) {
|
|
49
|
+
const category = this.pageSpecificData as IkasCategory;
|
|
50
|
+
filterCategoryId = category.id;
|
|
51
|
+
} else if (this.pageType === IkasThemeJsonPageType.BRAND) {
|
|
52
|
+
const brand = this.pageSpecificData as IkasBrand;
|
|
53
|
+
filterBrandId = brand.id;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (
|
|
59
|
+
this.productListPropValue.productListType ===
|
|
60
|
+
IkasProductListType.CATEGORY &&
|
|
61
|
+
this.productListPropValue.category
|
|
62
|
+
) {
|
|
63
|
+
filterCategoryId = this.productListPropValue.category;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (
|
|
67
|
+
this.pageType === IkasThemeJsonPageType.PRODUCT &&
|
|
68
|
+
this.productListPropValue.productListType ===
|
|
69
|
+
IkasProductListType.RELATED_PRODUCTS &&
|
|
70
|
+
this.productListPropValue.relatedProductsType &&
|
|
71
|
+
this.pageSpecificData
|
|
72
|
+
) {
|
|
73
|
+
this.relatedProductData = {
|
|
74
|
+
brandIds: null,
|
|
75
|
+
categoryIds: null,
|
|
76
|
+
productId: "",
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
if (
|
|
80
|
+
this.productListPropValue.relatedProductsType ===
|
|
81
|
+
IkasRelatedProductsType.CATEGORY
|
|
82
|
+
) {
|
|
83
|
+
this.relatedProductData.categoryIds =
|
|
84
|
+
this.pageSpecificData.product.categories.map(
|
|
85
|
+
(category: IkasCategory) => category.id
|
|
86
|
+
);
|
|
87
|
+
} else {
|
|
88
|
+
this.relatedProductData.brandIds = [
|
|
89
|
+
this.pageSpecificData.product?.brand?.id,
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
this.relatedProductData.productId = this.pageSpecificData.product.id;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const productList: IkasProductList = {
|
|
96
|
+
data: [],
|
|
97
|
+
count: 0,
|
|
98
|
+
page: 1,
|
|
99
|
+
limit: this.productListPropValue.initialLimit || 10,
|
|
100
|
+
type:
|
|
101
|
+
this.productListPropValue.productListType || IkasProductListType.ALL,
|
|
102
|
+
sort:
|
|
103
|
+
this.productListPropValue.initialSort ||
|
|
104
|
+
IkasProductListSortType.LAST_ADDED,
|
|
105
|
+
productListPropValue: this.productListPropValue,
|
|
106
|
+
filterBrandId,
|
|
107
|
+
filterCategoryId,
|
|
108
|
+
pageType: this.pageType,
|
|
109
|
+
pageSpecificData: [
|
|
110
|
+
IkasThemeJsonPageType.CATEGORY,
|
|
111
|
+
IkasThemeJsonPageType.BRAND,
|
|
112
|
+
].includes(this.pageType)
|
|
113
|
+
? this.pageSpecificData
|
|
114
|
+
: undefined,
|
|
115
|
+
relatedProductData: this.relatedProductData,
|
|
116
|
+
filters: null,
|
|
117
|
+
infiniteScrollPage: null,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
await getInitial(productList);
|
|
121
|
+
|
|
122
|
+
return productList;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import IkasPropValueProvider from ".";
|
|
2
|
+
import { IkasRaffleList } from "../../models/ui";
|
|
3
|
+
import { getInitial } from "../../models/ui/raffle-list/init";
|
|
4
|
+
|
|
5
|
+
export class IkasRaffleListPropValueProvider
|
|
6
|
+
implements IkasPropValueProvider<IkasRaffleList>
|
|
7
|
+
{
|
|
8
|
+
async getValue(): Promise<IkasRaffleList> {
|
|
9
|
+
const raffleList: IkasRaffleList = {
|
|
10
|
+
data: [],
|
|
11
|
+
count: 0,
|
|
12
|
+
page: 1,
|
|
13
|
+
limit: 20,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
await getInitial(raffleList);
|
|
17
|
+
|
|
18
|
+
return raffleList;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { listRaffle } from "@ikas/storefront-api";
|
|
2
|
+
import IkasPropValueProvider from ".";
|
|
3
|
+
import { IkasRafflePropValue } from "../../models/prop-value/raffle";
|
|
4
|
+
import { populateRaffleProducts } from "../helpers/raffle";
|
|
5
|
+
import { getPlaceholderRaffle } from "../placeholders";
|
|
6
|
+
import { IkasRafflePropValueData } from "../types";
|
|
7
|
+
|
|
8
|
+
export class IkasRafflePropValueProvider
|
|
9
|
+
implements IkasPropValueProvider<IkasRafflePropValueData | null>
|
|
10
|
+
{
|
|
11
|
+
private rafflePropValue: IkasRafflePropValue;
|
|
12
|
+
|
|
13
|
+
constructor(propValue: IkasRafflePropValue) {
|
|
14
|
+
this.rafflePropValue = propValue;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async getValue(): Promise<IkasRafflePropValueData | null> {
|
|
18
|
+
if (this.rafflePropValue?.usePageData) {
|
|
19
|
+
return {
|
|
20
|
+
raffle: null,
|
|
21
|
+
rafflePropValue: this.rafflePropValue,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (!this.rafflePropValue.raffleId) return null;
|
|
25
|
+
|
|
26
|
+
const rafflesResponse = await listRaffle({
|
|
27
|
+
id: { eq: this.rafflePropValue.raffleId },
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (!rafflesResponse.isSuccess || !rafflesResponse.data?.data?.length)
|
|
31
|
+
return null;
|
|
32
|
+
|
|
33
|
+
const raffle = rafflesResponse.data.data[0];
|
|
34
|
+
await populateRaffleProducts([raffle]);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
raffle: raffle || getPlaceholderRaffle(),
|
|
38
|
+
rafflePropValue: this.rafflePropValue,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import IkasPropValueProvider from ".";
|
|
2
|
+
|
|
3
|
+
export class IkasRichTextPropValueProvider
|
|
4
|
+
implements IkasPropValueProvider<string> {
|
|
5
|
+
private text: string;
|
|
6
|
+
|
|
7
|
+
constructor(textPropValue: string) {
|
|
8
|
+
this.text = textPropValue;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async getValue(): Promise<string> {
|
|
12
|
+
return this.text;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import IkasPropValueProvider from ".";
|
|
2
|
+
import { IkasSliderPropValueData } from "../types";
|
|
3
|
+
|
|
4
|
+
export class IkasSliderPropValueProvider
|
|
5
|
+
implements IkasPropValueProvider<IkasSliderPropValueData>
|
|
6
|
+
{
|
|
7
|
+
private sliderData: IkasSliderPropValueData;
|
|
8
|
+
|
|
9
|
+
constructor(sliderData: IkasSliderPropValueData) {
|
|
10
|
+
this.sliderData = sliderData;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async getValue(): Promise<IkasSliderPropValueData> {
|
|
14
|
+
return {
|
|
15
|
+
value: this.sliderData.value,
|
|
16
|
+
unit: this.sliderData.unit,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import IkasPropValueProvider from ".";
|
|
2
|
+
|
|
3
|
+
export class IkasTextPropValueProvider
|
|
4
|
+
implements IkasPropValueProvider<string> {
|
|
5
|
+
private text: string;
|
|
6
|
+
|
|
7
|
+
constructor(textPropValue: string) {
|
|
8
|
+
this.text = textPropValue;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async getValue(): Promise<string> {
|
|
12
|
+
return this.text;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IkasBlog,
|
|
3
|
+
IkasBlogCategory,
|
|
4
|
+
IkasBrand,
|
|
5
|
+
IkasCategory,
|
|
6
|
+
IkasProduct,
|
|
7
|
+
IkasProductOptionSet,
|
|
8
|
+
IkasRaffle,
|
|
9
|
+
IkasThemeJsonComponent,
|
|
10
|
+
IkasThemeJsonCustomData,
|
|
11
|
+
IkasThemeJsonPageComponent,
|
|
12
|
+
IkasVariantValue,
|
|
13
|
+
} from "@ikas/storefront-models";
|
|
14
|
+
import { IkasAttributeListPropValue } from "../models/prop-value/attribute-list";
|
|
15
|
+
import { IkasAttributePropValue } from "../models/prop-value/attribute";
|
|
16
|
+
import { IkasBlogCategoryPropValue } from "../models/prop-value/blog-category";
|
|
17
|
+
import { IkasBlogPropValue } from "../models/prop-value/blog";
|
|
18
|
+
import { IkasBrandPropValue } from "../models/prop-value/brand";
|
|
19
|
+
import { IkasCategoryPropValue } from "../models/prop-value/category";
|
|
20
|
+
import { IkasProductPropValue } from "../models/prop-value/product";
|
|
21
|
+
import { IkasRafflePropValue } from "../models/prop-value/raffle";
|
|
22
|
+
|
|
23
|
+
export class IkasPageComponentPropValue {
|
|
24
|
+
pageComponent: IkasThemeJsonPageComponent;
|
|
25
|
+
component: IkasThemeJsonComponent;
|
|
26
|
+
propValues: Record<string, any>;
|
|
27
|
+
|
|
28
|
+
constructor(data: IkasPageComponentPropValue) {
|
|
29
|
+
this.pageComponent = data.pageComponent;
|
|
30
|
+
this.component = data.component;
|
|
31
|
+
this.propValues = data.propValues || {};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type IkasAttributeListPropValueData = {
|
|
36
|
+
productDetail: IkasProduct | null;
|
|
37
|
+
attributeListPropValue: IkasAttributeListPropValue;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type IkasAttributePropValueData = {
|
|
41
|
+
productDetail: IkasProductPropValueProduct | null;
|
|
42
|
+
attributePropValue: IkasAttributePropValue;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type IkasBlogCategoryPropValueData = {
|
|
46
|
+
blogCategory: IkasBlogCategory | null;
|
|
47
|
+
blogCategoryPropValue: IkasBlogCategoryPropValue;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type IkasBlogPropValueData = {
|
|
51
|
+
blog: IkasBlog | null;
|
|
52
|
+
blogPropValue: IkasBlogPropValue;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type IkasBrandPropValueData = {
|
|
56
|
+
brand: IkasBrand | null;
|
|
57
|
+
brandPropValue: IkasBrandPropValue;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type IkasCategoryPropValueData = {
|
|
61
|
+
category: IkasCategory | null;
|
|
62
|
+
categoryPropValue: IkasCategoryPropValue;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type IkasCustomDataPropValueData = {
|
|
66
|
+
value: any;
|
|
67
|
+
customData: IkasThemeJsonCustomData;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type IkasProductPropValueProduct = {
|
|
71
|
+
productOptionSet?: IkasProductOptionSet | null;
|
|
72
|
+
selectedVariantValues?: IkasVariantValue[] | null;
|
|
73
|
+
} & IkasProduct;
|
|
74
|
+
|
|
75
|
+
export type IkasProductPropValueData = {
|
|
76
|
+
productDetailPropValue: IkasProductPropValue;
|
|
77
|
+
productDetail: IkasProductPropValueProduct | null;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export type IkasRafflePropValueData = {
|
|
81
|
+
raffle: IkasRaffle | null;
|
|
82
|
+
rafflePropValue: IkasRafflePropValue;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export type IkasSliderPropValueData = {
|
|
86
|
+
value: number;
|
|
87
|
+
unit: string | null;
|
|
88
|
+
};
|