mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
ensure products have at least one variant
This commit is contained in:
@@ -110,6 +110,7 @@ const normalizeProductVariants = (
|
||||
export function normalizeProduct(swellProduct: SwellProduct): Product {
|
||||
const {
|
||||
id,
|
||||
name,
|
||||
description,
|
||||
images,
|
||||
options,
|
||||
@@ -118,6 +119,8 @@ export function normalizeProduct(swellProduct: SwellProduct): Product {
|
||||
price: value,
|
||||
currency: currencyCode,
|
||||
} = swellProduct
|
||||
// ProductView accesses variants for each product
|
||||
const emptyVariants = [{ options: [], id, name }]
|
||||
const productOptions = options
|
||||
? options.map((o) => normalizeProductOption(o))
|
||||
: []
|
||||
@@ -133,7 +136,10 @@ export function normalizeProduct(swellProduct: SwellProduct): Product {
|
||||
vendor: '',
|
||||
path: `/${slug}`,
|
||||
images: productImages,
|
||||
variants: productVariants,
|
||||
variants:
|
||||
productVariants && productVariants.length
|
||||
? productVariants
|
||||
: emptyVariants,
|
||||
options: productOptions,
|
||||
price: {
|
||||
value,
|
||||
|
Reference in New Issue
Block a user