bug fixes for cart actions

This commit is contained in:
Luis Alvarez
2020-10-07 15:08:17 -05:00
parent 80614a1df0
commit 3ac6805ebe
8 changed files with 47 additions and 34 deletions

View File

@@ -146,14 +146,18 @@ const cartApi: BigcommerceApiHandler<Cart> = async (req, res, config) => {
`/v3/carts/${cartId}/items/${itemId}`,
{ method: 'DELETE' }
)
const data = result?.data ?? null
// Update the cart cookie
res.setHeader(
'Set-Cookie',
getCartCookie(config.cartCookie, cartId, config.cartCookieMaxAge)
data
? // Update the cart cookie
getCartCookie(config.cartCookie, cartId, config.cartCookieMaxAge)
: // Remove the cart cookie if the cart was removed (empty items)
getCartCookie(config.cartCookie)
)
return res.status(200).json({ data: result?.data })
return res.status(200).json({ data })
}
} catch (error) {
console.error(error)