Skip to content

Commit

Permalink
fix: set empty arrays for undefined array types
Browse files Browse the repository at this point in the history
  • Loading branch information
Benj0s committed Jan 14, 2025
1 parent 9adc2aa commit 10bdad7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/codec/codecs/commerce/scayle/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const mapProduct = (product: ScayleProduct): Product | null => {
id: String(product.id),
name: product.attributes?.name?.values?.label,
slug: product.referenceKey,
categories: product.attributes?.category?.values?.map(mapProductCategory),
variants: product.variants?.map(mapProductVariants),
categories: product.attributes?.category?.values?.map(mapProductCategory) || [],
variants: product.variants?.map(mapProductVariants) || [],
shortDescription: product.attributes?.description?.values?.label,
longDescription: product.attributes?.description?.values?.label
}
Expand All @@ -34,11 +34,11 @@ export const mapProductVariants = (variant: ScaylaProductVariant): Variant => {
return {
id: String(variant.id),
sku: variant.referenceKey,
listPrice: formatMoneyString(variant.price.withTax, {
currency: variant.price.currencyCode
listPrice: formatMoneyString(variant.price?.withTax, {
currency: variant.price?.currencyCode
}),
salePrice: formatMoneyString(variant.price.withTax, {
currency: variant.price.currencyCode
salePrice: formatMoneyString(variant.price?.withTax, {
currency: variant.price?.currencyCode
}),
attributes: undefined,
images: undefined
Expand All @@ -50,7 +50,7 @@ export const mapCategory = (category: ScayleCategory): Category => {
id: String(category.id),
name: category.name,
slug: category.slug,
children: category.children.map(mapCategory),
children: category.children?.map(mapCategory) || [],
products: [],
showInMenu: !category.isHidden
}
Expand Down

0 comments on commit 10bdad7

Please sign in to comment.