fix: Clean order if it is placed

This commit is contained in:
Alessandro Casazza 2022-01-05 10:43:42 +01:00
parent 217a8f34c0
commit 0f5cdf99fb
No known key found for this signature in database
GPG Key ID: 3AF41B06C6495D3D
2 changed files with 42 additions and 33 deletions

View File

@ -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 {

View File

@ -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: '',