Create a new cart if current cart is not active/has been paid

This commit is contained in:
2021-11-15 17:02:44 +01:00
parent 68e7b0eccd
commit 5080fadd60

View File

@@ -23,9 +23,31 @@
}) })
if (existantCart.ok) { if (existantCart.ok) {
const cart = await existantCart.json() const cart = await existantCart.json()
$cartId = cart.id
$cartData = cart
// console.log('Fetched existant cart:', $cartId, $cartData) // 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
$cartData = cart
}
// 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