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,5 +1,9 @@
|
||||
export default function normalizeLineItems(lineItems: any[]) {
|
||||
return lineItems.map((lineItem) => {
|
||||
return lineItems
|
||||
.filter((l) => {
|
||||
return !['shipment', 'paymentMethod'].includes(l.itemType)
|
||||
})
|
||||
.map((lineItem) => {
|
||||
const id = lineItem.id
|
||||
const attributes = lineItem.attributes
|
||||
return {
|
||||
|
@ -18,6 +18,8 @@ export const handler: SWRHook<any> = {
|
||||
const clOrder = await Order.withCredentials(credentials)
|
||||
.includes('lineItems')
|
||||
.find(id, { rawResponse: true })
|
||||
const orderStatus = clOrder.status
|
||||
if (['pending', 'draft'].includes(orderStatus)) {
|
||||
const attributes = clOrder.data.attributes
|
||||
const lineItems = clOrder?.included
|
||||
? normalizeLineItems(clOrder?.included)
|
||||
@ -32,6 +34,9 @@ export const handler: SWRHook<any> = {
|
||||
subtotalPrice: attributes.subtotal_amount_float,
|
||||
totalPrice: attributes.total_amount_float,
|
||||
}
|
||||
} else {
|
||||
localStorage.removeItem('CL_ORDER_ID')
|
||||
}
|
||||
}
|
||||
return {
|
||||
id: '',
|
||||
|
Loading…
x
Reference in New Issue
Block a user