mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Normalized Options and Swatches
This commit is contained in:
@@ -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
12
framework/types.d.ts
vendored
@@ -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
|
||||
|
Reference in New Issue
Block a user