mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 07:26:59 +00:00
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import data from '../../data.json'
|
|
|
|
export default function normalizeLineItems(lineItems: any[]) {
|
|
return lineItems
|
|
.filter((l) => {
|
|
return !['shipment', 'paymentMethod'].includes(l.itemType)
|
|
})
|
|
.map((lineItem) => {
|
|
const id = lineItem.id
|
|
const attributes = lineItem.attributes
|
|
const products = data.products
|
|
return {
|
|
id,
|
|
name: attributes.name,
|
|
path: products.find((p) => p.id === attributes.reference)?.slug,
|
|
productId: attributes.reference,
|
|
variantId: attributes.reference,
|
|
quantity: attributes.quantity,
|
|
price: attributes.unit_amount_float,
|
|
variant: {
|
|
id,
|
|
name: attributes.name,
|
|
sku: attributes.sku_code,
|
|
price: attributes.unit_amount_float,
|
|
image: {
|
|
url: `https://data.commercelayer.app/vercel-provider/${attributes.reference}_FLAT.png`,
|
|
altText: attributes.name,
|
|
width: 1000,
|
|
height: 1000,
|
|
},
|
|
},
|
|
}
|
|
})
|
|
}
|