forked from crowetic/commerce
* Remove duplicated css rules. (#185) * Fix typo in the Marquee component (#176) Co-authored-by: Hugo Lopes <hugo.lopes@present-technologies.com> * Remove duplicated css rules. Fix invalid JSX props. Co-authored-by: Hugo Lopes <hugo.lopes@present-technologies.com> * Fix the body scroll when the sidebar is open (#184) * Fix typo in the Marquee component (#176) Co-authored-by: Hugo Lopes <hugo.lopes@present-technologies.com> * Fix the body scroll when the sidebar is open Co-authored-by: Hugo Lopes <hugo.lopes@present-technologies.com> * Remove duplicate class in the I18nWidget comp (#183) * Fix typo in the Marquee component (#176) Co-authored-by: Hugo Lopes <hugo.lopes@present-technologies.com> * Remove duplicate class name in the I18nWidget comp This PR removes a duplicate class name in the I18nWidget component. Co-authored-by: Hugo Lopes <hugo.rodrigues.lopes@gmail.com> Co-authored-by: Hugo Lopes <hugo.lopes@present-technologies.com> * add horizontal margin to pages when mobile screen (#180) * Add cart item options like color and size (#177) Co-authored-by: hlopes <hugo.lopes@present-technologies.com> * Changes Co-authored-by: Hugo Lopes <hugo.rodrigues.lopes@gmail.com> Co-authored-by: Hugo Lopes <hugo.lopes@present-technologies.com> Co-authored-by: Jamie Isaksen <jamie@jamie.no> Co-authored-by: Vinicius Zucatti <51221635+vczb@users.noreply.github.com>
35 lines
922 B
TypeScript
35 lines
922 B
TypeScript
import getCartCookie from '../../utils/get-cart-cookie'
|
|
import type { CartHandlers } from '..'
|
|
|
|
// Return current cart info
|
|
const removeItem: CartHandlers['removeItem'] = async ({
|
|
res,
|
|
body: { cartId, itemId },
|
|
config,
|
|
}) => {
|
|
if (!cartId || !itemId) {
|
|
return res.status(400).json({
|
|
data: null,
|
|
errors: [{ message: 'Invalid request' }],
|
|
})
|
|
}
|
|
|
|
const result = await config.storeApiFetch<{ data: any } | null>(
|
|
`/v3/carts/${cartId}/items/${itemId}?include=line_items.physical_items.options`,
|
|
{ method: 'DELETE' }
|
|
)
|
|
const data = result?.data ?? null
|
|
|
|
res.setHeader(
|
|
'Set-Cookie',
|
|
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)
|
|
)
|
|
res.status(200).json({ data })
|
|
}
|
|
|
|
export default removeItem
|