mirror of
https://github.com/vercel/commerce.git
synced 2025-07-25 19:21:23 +00:00
Checkout changes
This commit is contained in:
@@ -29,36 +29,35 @@ export const handler: MutationHook<AddItemHook> = {
|
||||
})
|
||||
}
|
||||
|
||||
const lineItems = [
|
||||
{
|
||||
variantId: item.variantId,
|
||||
quantity: item.quantity ?? 1,
|
||||
},
|
||||
]
|
||||
|
||||
let checkoutId = getCheckoutId()
|
||||
|
||||
if (!checkoutId) {
|
||||
const checkout = await checkoutCreate(fetch)
|
||||
checkoutId = checkout.id
|
||||
return checkoutToCart(await checkoutCreate(fetch, lineItems))
|
||||
} else {
|
||||
const { checkoutLineItemsAdd } = await fetch<
|
||||
Mutation,
|
||||
MutationCheckoutLineItemsAddArgs
|
||||
>({
|
||||
...options,
|
||||
variables: {
|
||||
checkoutId,
|
||||
lineItems,
|
||||
},
|
||||
})
|
||||
return checkoutToCart(checkoutLineItemsAdd)
|
||||
}
|
||||
|
||||
const { checkoutLineItemsAdd } = await fetch<
|
||||
Mutation,
|
||||
MutationCheckoutLineItemsAddArgs
|
||||
>({
|
||||
...options,
|
||||
variables: {
|
||||
checkoutId,
|
||||
lineItems: [
|
||||
{
|
||||
variantId: item.variantId,
|
||||
quantity: item.quantity ?? 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
return checkoutToCart(checkoutLineItemsAdd)
|
||||
},
|
||||
useHook:
|
||||
({ fetch }) =>
|
||||
() => {
|
||||
const { mutate } = useCart()
|
||||
|
||||
return useCallback(
|
||||
async function addItem(input) {
|
||||
const data = await fetch({ input })
|
||||
|
Reference in New Issue
Block a user