mirror of
https://github.com/vercel/commerce.git
synced 2025-07-24 10:41:23 +00:00
handle empty cart, variants, options, errors
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import { Product } from '@commerce/types'
|
||||
import { getConfig, SwellConfig } from '../api'
|
||||
import fetchAllProducts from '../api/utils/fetch-all-products'
|
||||
import { ProductEdge } from '../schema'
|
||||
|
||||
type ProductPath = {
|
||||
path: string
|
||||
@@ -20,7 +18,7 @@ const getAllProductPaths = async (options?: {
|
||||
config?: SwellConfig
|
||||
preview?: boolean
|
||||
}): Promise<ReturnType> => {
|
||||
let { config, variables = { limit: 100 } } = options ?? {}
|
||||
let { config, variables = [{ limit: 100 }] } = options ?? {}
|
||||
config = getConfig(config)
|
||||
|
||||
const products = await fetchAllProducts({
|
||||
|
@@ -19,11 +19,11 @@ const getProduct = async (options: {
|
||||
config = getConfig(config)
|
||||
|
||||
const product = await config.fetchSwell('products', 'get', [variables.slug])
|
||||
if (product.variants) {
|
||||
if (product && product.variants) {
|
||||
product.variants = product.variants?.results
|
||||
}
|
||||
return {
|
||||
product: normalizeProduct(product),
|
||||
product: product ? normalizeProduct(product) : null,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user