Implement variants and options

This commit is contained in:
goncy
2021-08-10 10:51:53 -03:00
parent 04f9799636
commit 07bc16b9a7
6 changed files with 113 additions and 80 deletions

View File

@@ -12,49 +12,32 @@ export function normalize(product: RawProduct): Product {
value: product.xp.Price,
currencyCode: product.xp.PriceCurrency,
},
// TODO: Implement this
variants: [
{
id: 'unique',
options: [
{
id: 'unique',
displayName: 'Model',
values: [
{
label: 'Unique',
},
],
},
],
},
],
options: [
{
id: 'option-color',
displayName: 'Color',
values: [
{
label: 'color',
hexColors: ['#222'],
},
],
},
{
id: 'option-size',
displayName: 'Size',
values: [
{
label: 'S',
},
{
label: 'M',
},
{
label: 'L',
},
],
},
],
// Variants are not always present, in case they are not, return a single unique variant
variants:
product.VariantCount === 0
? [
{
id: 'unique',
options: [
{
id: 'unique',
displayName: 'Unique',
values: [{ label: 'Unique' }],
},
],
},
]
: [],
// Facets are not always present, just iterate them if they are
options: product.xp.Facets
? Object.entries(product.xp.Facets).map(([key, values]) => ({
id: key,
displayName: key,
__typename: 'MultipleChoiceOption',
values: values.map((value) => ({
label: value,
})),
}))
: [],
}
}