forked from vercel/commerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepopack-output.txt
164 lines (143 loc) · 4.16 KB
/
repopack-output.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
Help me finnish this reshaping of a product for a product card.
Here is the Types:
export type ProductType = {
id: string;
seo: {
title?: string;
description?: string;
};
currency: string;
slug: string;
handle: string;
stockTracking: boolean;
stockPurchasable: boolean;
stockLevel: number;
title: string;
name: string;
description: string;
price: string;
priceRange: {
maxVariantPrice: MoneyType;
minVariantPrice: MoneyType;
};
metaTitle: string;
metaDescription: string;
tags: string[];
options: ProductOptionType[];
variants: ProductVariantType[];
featuredImage: ProductImageType;
images: ProductImageType[];
updatedAt?: string;
availableForSale: boolean;
descriptionHtml?: string;
relations?: ProductRelationType[];
};
export type ProductOptionType = {
id: string;
name: string;
values: string[];
};
export type ProductOptionValueType = {
id: string;
name: string;
price: number;
};
export type ProductVariantType = {
id: string;
title: string;
availableForSale: boolean;
selectedOptions: {
name: string;
value: string;
}[];
price: MoneyType;
};
Here is what i got so far:
const reshapeProduct = (geinsProductData: any): ProductType => {
const rawProduct = geinsProductData;
const tags: string[] = [];
const relations: ProductRelationType[] = [];
if (rawProduct.primaryCategory) {
tags.push(rawProduct.primaryCategory.name);
relations.push({
type: ProductRelationTypeEnum.CATEGORY,
name: rawProduct.primaryCategory.name,
alias: rawProduct.primaryCategory.alias,
});
}
if (rawProduct.brand) {
tags.push(rawProduct.brand.name);
relations.push({
type: ProductRelationTypeEnum.BRAND,
name: rawProduct.brand.name,
alias: rawProduct.brand.alias,
});
}
if(rawProduct.categories) {
rawProduct.categories.forEach((category: any) => {
tags.push(category.name);
});
}
// remove duplicates
const uniqueTags = [...new Set(tags)];
tags.push(...uniqueTags);
// add descriptions from environment variables
const shortDescription = rawProduct.texts?.[SHORT_DESCRIPTION] || '';
const longDescription = rawProduct.texts?.[LONG_DESCRIPTION] || '';
// add images
const images = rawProduct.productImages?.map((image: any): ProductImageType => ({
caption: rawProduct.name,
altText: rawProduct.name,
src: `${IMAGE_URL}/product/1200f1500/${image.fileName}`,
url: `${IMAGE_URL}/product/1200f1500/${image.fileName}`,
height: 1600,
width: 2000,
}));
// add variations and options
const variations: ProductVariantType[] = reshapeProductVariations(rawProduct);
const options: ProductOptionType[] = reshapeProductOptions(rawProduct);
return {
id: rawProduct.productId,
seo: {
title: rawProduct.meta?.title,
description: rawProduct.meta?.description,
},
metaTitle: rawProduct.meta?.title || rawProduct.name,
metaDescription: rawProduct.meta?.description || shortDescription,
name: rawProduct.name,
title: rawProduct.name,
slug: rawProduct.alias,
handle: rawProduct.alias,
description: shortDescription,
descriptionHtml: rawProduct.texts?.text1 || '',
priceRange: {
minVariantPrice: {
amount: rawProduct.unitPrice?.sellingPriceIncVat,
currencyCode: CURRENCY_CODE,
},
maxVariantPrice: {
amount: rawProduct.unitPrice?.sellingPriceIncVat,
currencyCode: CURRENCY_CODE,
},
},
price: rawProduct.unitPrice.sellingPriceIncVat,
currency: CURRENCY_CODE,
stockTracking: !!rawProduct.totalStock,
stockPurchasable: rawProduct.totalStock?.inStock || false,
stockLevel: rawProduct.totalStock?.totalStock || 0,
availableForSale: true,
tags: tags || [],
options: [...options]|| [],
variants: variations || [],
featuredImage: images[0],
images: images,
relations: relations,
};
};
const reshapeProductVariations = (geinsProductData: any): ProductVariantType[] => {
return [];
};
const reshapeProductOptions = (geinsProductData: any): ProductOptionType[] => {
return [];
};
And here is the query to API in graphql