Normalized Options and Swatches

This commit is contained in:
Belen Curcio
2021-01-11 14:54:05 -03:00
parent dccc5ef430
commit 4fdaae2197
4 changed files with 38 additions and 11 deletions

View File

@@ -8,6 +8,7 @@ export function normalizeProduct(productNode: BCProduct): Product {
productOptions,
prices,
path,
options: _,
...rest
} = productNode
@@ -29,8 +30,20 @@ export function normalizeProduct(productNode: BCProduct): Product {
...rest,
}))
: [],
productOptions: productOptions.edges
? productOptions.edges.map(({ node }: any) => node)
options: productOptions.edges
? productOptions.edges.map(
({
node: {
entityId,
values: { edges },
...rest
},
}: any) => ({
id: entityId,
values: edges.map(({ node }: any) => node),
...rest,
})
)
: [],
price: {
value: prices?.price.value,

12
framework/types.d.ts vendored
View File

@@ -11,7 +11,19 @@ interface Product extends Entity {
images: ProductImage[]
variants: ProductVariant[]
price: ProductPrice
options: ProductOption[]
}
interface ProductOption extends Entity {
displayName: string
values: ProductOptionValues[]
}
interface ProductOptionValues {
label: string
hexColors?: string[]
}
interface ProductImage {
url: string
alt?: string