mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
feat: disable Wishlist
chore: setup commerce & next config fix: replace all call to bigcommerce from aquilacms provider feat add validation to input in signup
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { parseCartItem } from '../../utils/parse-item'
|
||||
import getCartCookie from '../../utils/get-cart-cookie'
|
||||
import type { CartHandlers } from '..'
|
||||
import { AquilacmsCart } from '../../../types'
|
||||
import { normalizeCart } from '../../../lib/normalize'
|
||||
|
||||
const addItem: CartHandlers['addItem'] = async ({
|
||||
res,
|
||||
@@ -14,32 +15,23 @@ const addItem: CartHandlers['addItem'] = async ({
|
||||
})
|
||||
}
|
||||
if (!item.quantity) item.quantity = 1
|
||||
|
||||
const options = {
|
||||
method: 'POST',
|
||||
const result: AquilacmsCart = await config.storeApiFetch('/v2/cart/item', {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({
|
||||
line_items: [parseCartItem(item)],
|
||||
...(!cartId && config.storeChannelId
|
||||
? { channel_id: config.storeChannelId }
|
||||
: {}),
|
||||
cartId,
|
||||
item: {
|
||||
id: item.productId,
|
||||
quantity: item.quantity,
|
||||
},
|
||||
}),
|
||||
}
|
||||
const { data } = cartId
|
||||
? await config.storeApiFetch(
|
||||
`/v3/carts/${cartId}/items?include=line_items.physical_items.options`,
|
||||
options
|
||||
)
|
||||
: await config.storeApiFetch(
|
||||
'/v3/carts?include=line_items.physical_items.options',
|
||||
options
|
||||
)
|
||||
})
|
||||
|
||||
// Create or update the cart cookie
|
||||
res.setHeader(
|
||||
'Set-Cookie',
|
||||
getCartCookie(config.cartCookie, data.id, config.cartCookieMaxAge)
|
||||
getCartCookie(config.cartCookie, result._id, config.cartCookieMaxAge)
|
||||
)
|
||||
res.status(200).json({ data })
|
||||
res.status(200).json({ data: normalizeCart(result) })
|
||||
}
|
||||
|
||||
export default addItem
|
||||
|
@@ -2,6 +2,7 @@ import type { AquilacmsCart } from '../../../types'
|
||||
import { AquilacmsApiError } from '../../utils/errors'
|
||||
import getCartCookie from '../../utils/get-cart-cookie'
|
||||
import type { CartHandlers } from '..'
|
||||
import { normalizeCart } from '../../../lib/normalize'
|
||||
|
||||
// Return current cart info
|
||||
const getCart: CartHandlers['getCart'] = async ({
|
||||
@@ -9,13 +10,21 @@ const getCart: CartHandlers['getCart'] = async ({
|
||||
body: { cartId },
|
||||
config,
|
||||
}) => {
|
||||
let result: { data?: AquilacmsCart } = {}
|
||||
|
||||
if (cartId) {
|
||||
try {
|
||||
result = await config.storeApiFetch(
|
||||
`/v3/carts/${cartId}?include=line_items.physical_items.options`
|
||||
let result: AquilacmsCart = await config.storeApiFetch(
|
||||
`/v2/cart/${cartId}`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
lang: 'en',
|
||||
PostBody: {
|
||||
populate: ['items.id'],
|
||||
},
|
||||
}),
|
||||
}
|
||||
)
|
||||
return res.status(200).json({ data: normalizeCart(result) })
|
||||
} catch (error) {
|
||||
if (error instanceof AquilacmsApiError && error.status === 404) {
|
||||
// Remove the cookie if it exists but the cart wasn't found
|
||||
@@ -25,8 +34,7 @@ const getCart: CartHandlers['getCart'] = async ({
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res.status(200).json({ data: result.data ?? null })
|
||||
res.status(200).json({ data: null })
|
||||
}
|
||||
|
||||
export default getCart
|
||||
|
@@ -1,5 +1,7 @@
|
||||
import getCartCookie from '../../utils/get-cart-cookie'
|
||||
import type { CartHandlers } from '..'
|
||||
import { AquilacmsCart } from '../../../types'
|
||||
import { normalizeCart } from '../../../lib/normalize'
|
||||
|
||||
const removeItem: CartHandlers['removeItem'] = async ({
|
||||
res,
|
||||
@@ -13,11 +15,13 @@ const removeItem: CartHandlers['removeItem'] = async ({
|
||||
})
|
||||
}
|
||||
|
||||
const result = await config.storeApiFetch<{ data: any } | null>(
|
||||
`/v3/carts/${cartId}/items/${itemId}?include=line_items.physical_items.options`,
|
||||
{ method: 'DELETE' }
|
||||
const result: AquilacmsCart = await config.storeApiFetch(
|
||||
`/v2/cart/${cartId}/item/${itemId}`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
}
|
||||
)
|
||||
const data = result?.data ?? null
|
||||
let data = normalizeCart(result) ?? null
|
||||
|
||||
res.setHeader(
|
||||
'Set-Cookie',
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { parseCartItem } from '../../utils/parse-item'
|
||||
import getCartCookie from '../../utils/get-cart-cookie'
|
||||
import type { CartHandlers } from '..'
|
||||
import { AquilacmsCart } from '../../../types'
|
||||
import { normalizeCart } from '../../../lib/normalize'
|
||||
|
||||
const updateItem: CartHandlers['updateItem'] = async ({
|
||||
res,
|
||||
@@ -14,14 +15,19 @@ const updateItem: CartHandlers['updateItem'] = async ({
|
||||
})
|
||||
}
|
||||
|
||||
const { data } = await config.storeApiFetch(
|
||||
`/v3/carts/${cartId}/items/${itemId}?include=line_items.physical_items.options`,
|
||||
{
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({
|
||||
line_item: parseCartItem(item),
|
||||
}),
|
||||
}
|
||||
const options = {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({
|
||||
item: {
|
||||
_id: itemId,
|
||||
quantity: item.quantity,
|
||||
},
|
||||
cartId,
|
||||
}),
|
||||
}
|
||||
const result: AquilacmsCart = await config.storeApiFetch(
|
||||
'/v2/cart/updateqty',
|
||||
options
|
||||
)
|
||||
|
||||
// Update the cart cookie
|
||||
@@ -29,7 +35,7 @@ const updateItem: CartHandlers['updateItem'] = async ({
|
||||
'Set-Cookie',
|
||||
getCartCookie(config.cartCookie, cartId, config.cartCookieMaxAge)
|
||||
)
|
||||
res.status(200).json({ data })
|
||||
res.status(200).json({ data: normalizeCart(result) })
|
||||
}
|
||||
|
||||
export default updateItem
|
||||
|
Reference in New Issue
Block a user