mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 07:26:59 +00:00
fix: Clean order if it is placed
This commit is contained in:
parent
217a8f34c0
commit
0f5cdf99fb
@ -1,26 +1,30 @@
|
|||||||
export default function normalizeLineItems(lineItems: any[]) {
|
export default function normalizeLineItems(lineItems: any[]) {
|
||||||
return lineItems.map((lineItem) => {
|
return lineItems
|
||||||
const id = lineItem.id
|
.filter((l) => {
|
||||||
const attributes = lineItem.attributes
|
return !['shipment', 'paymentMethod'].includes(l.itemType)
|
||||||
return {
|
})
|
||||||
id,
|
.map((lineItem) => {
|
||||||
name: attributes.name,
|
const id = lineItem.id
|
||||||
productId: attributes.reference,
|
const attributes = lineItem.attributes
|
||||||
variantId: attributes.reference,
|
return {
|
||||||
quantity: attributes.quantity,
|
|
||||||
price: attributes.unit_amount_float,
|
|
||||||
variant: {
|
|
||||||
id,
|
id,
|
||||||
name: attributes.name,
|
name: attributes.name,
|
||||||
sku: attributes.sku_code,
|
productId: attributes.reference,
|
||||||
|
variantId: attributes.reference,
|
||||||
|
quantity: attributes.quantity,
|
||||||
price: attributes.unit_amount_float,
|
price: attributes.unit_amount_float,
|
||||||
image: {
|
variant: {
|
||||||
url: `/commercelayer_assets/${attributes.reference}_FLAT.png`,
|
id,
|
||||||
altText: 'Black Women Long Sleeve Shirt',
|
name: attributes.name,
|
||||||
width: 1000,
|
sku: attributes.sku_code,
|
||||||
height: 1000,
|
price: attributes.unit_amount_float,
|
||||||
|
image: {
|
||||||
|
url: `/commercelayer_assets/${attributes.reference}_FLAT.png`,
|
||||||
|
altText: 'Black Women Long Sleeve Shirt',
|
||||||
|
width: 1000,
|
||||||
|
height: 1000,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
}
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
@ -18,19 +18,24 @@ export const handler: SWRHook<any> = {
|
|||||||
const clOrder = await Order.withCredentials(credentials)
|
const clOrder = await Order.withCredentials(credentials)
|
||||||
.includes('lineItems')
|
.includes('lineItems')
|
||||||
.find(id, { rawResponse: true })
|
.find(id, { rawResponse: true })
|
||||||
const attributes = clOrder.data.attributes
|
const orderStatus = clOrder.status
|
||||||
const lineItems = clOrder?.included
|
if (['pending', 'draft'].includes(orderStatus)) {
|
||||||
? normalizeLineItems(clOrder?.included)
|
const attributes = clOrder.data.attributes
|
||||||
: []
|
const lineItems = clOrder?.included
|
||||||
return {
|
? normalizeLineItems(clOrder?.included)
|
||||||
id,
|
: []
|
||||||
createdAt: attributes.created_at,
|
return {
|
||||||
currency: { code: attributes.currency_code },
|
id,
|
||||||
taxesIncluded: '',
|
createdAt: attributes.created_at,
|
||||||
lineItems,
|
currency: { code: attributes.currency_code },
|
||||||
lineItemsSubtotalPrice: '',
|
taxesIncluded: '',
|
||||||
subtotalPrice: attributes.subtotal_amount_float,
|
lineItems,
|
||||||
totalPrice: attributes.total_amount_float,
|
lineItemsSubtotalPrice: '',
|
||||||
|
subtotalPrice: attributes.subtotal_amount_float,
|
||||||
|
totalPrice: attributes.total_amount_float,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
localStorage.removeItem('CL_ORDER_ID')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user