Create a new cart if current cart is not active/has been paid
This commit is contained in:
@@ -23,9 +23,31 @@
|
|||||||
})
|
})
|
||||||
if (existantCart.ok) {
|
if (existantCart.ok) {
|
||||||
const cart = await existantCart.json()
|
const cart = await existantCart.json()
|
||||||
|
// console.log('Fetched existant cart:', $cartId, $cartData)
|
||||||
|
|
||||||
|
// Cart is active / has not been ordered
|
||||||
|
if (cart.active || !cart.order_id) {
|
||||||
|
// Keep current cart
|
||||||
$cartId = cart.id
|
$cartId = cart.id
|
||||||
$cartData = cart
|
$cartData = cart
|
||||||
// console.log('Fetched existant cart:', $cartId, $cartData)
|
}
|
||||||
|
|
||||||
|
// Cart is inactive / has been ordered
|
||||||
|
else {
|
||||||
|
// Fetch a new cart
|
||||||
|
const newCart = await fetch('/api/swell', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
action: 'createCart'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
if (newCart.ok) {
|
||||||
|
const cart = await newCart.json()
|
||||||
|
// Save new cart
|
||||||
|
$cartId = cart.id
|
||||||
|
$cartData = cart
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Cart doesn't exists
|
// Cart doesn't exists
|
||||||
|
|||||||
Reference in New Issue
Block a user