mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 21:51:21 +00:00
saleor: adding/removing from the cart
This commit is contained in:
parent
2c097b0f7e
commit
7d80fadd82
@ -16,7 +16,7 @@ import {
|
||||
checkoutToCart,
|
||||
} from '../utils'
|
||||
import { Cart, LineItem } from '../types'
|
||||
import { Mutation, MutationCheckoutLineItemsRemoveArgs } from '../schema'
|
||||
import { Mutation, MutationCheckoutLineDeleteArgs } from '../schema'
|
||||
|
||||
export type RemoveItemFn<T = any> = T extends LineItem
|
||||
? (input?: RemoveItemInput<T>) => Promise<Cart | null>
|
||||
@ -37,11 +37,14 @@ export const handler = {
|
||||
options,
|
||||
fetch,
|
||||
}: HookFetcherContext<RemoveCartItemBody>) {
|
||||
const data = await fetch<Mutation, MutationCheckoutLineItemsRemoveArgs>({
|
||||
const data = await fetch<Mutation, MutationCheckoutLineDeleteArgs>({
|
||||
...options,
|
||||
variables: { checkoutId: getCheckoutId(), lineItemIds: [itemId] },
|
||||
variables: {
|
||||
checkoutId: getCheckoutId().checkoutId,
|
||||
lineId: itemId
|
||||
},
|
||||
})
|
||||
return checkoutToCart(data.checkoutLineItemsRemove)
|
||||
return checkoutToCart(data.checkoutLinesUpdate)
|
||||
},
|
||||
useHook: ({
|
||||
fetch,
|
||||
|
@ -15,7 +15,7 @@ import { handler as removeItemHandler } from './use-remove-item'
|
||||
import type { Cart, LineItem, UpdateCartItemBody } from '../types'
|
||||
import { checkoutToCart } from '../utils'
|
||||
import { getCheckoutId, checkoutLineItemUpdateMutation } from '../utils'
|
||||
import { Mutation, MutationCheckoutLineItemsUpdateArgs } from '../schema'
|
||||
import { Mutation, MutationCheckoutLinesUpdateArgs } from '../schema'
|
||||
|
||||
export type UpdateItemInput<T = any> = T extends LineItem
|
||||
? Partial<UpdateItemInputBase<LineItem>>
|
||||
@ -46,23 +46,25 @@ export const handler = {
|
||||
message: 'The item quantity has to be a valid integer',
|
||||
})
|
||||
}
|
||||
const { checkoutLineItemsUpdate } = await fetch<
|
||||
|
||||
const checkoutId = getCheckoutId().checkoutId;
|
||||
const { checkoutLinesUpdate } = await fetch<
|
||||
Mutation,
|
||||
MutationCheckoutLineItemsUpdateArgs
|
||||
MutationCheckoutLinesUpdateArgs
|
||||
>({
|
||||
...options,
|
||||
variables: {
|
||||
checkoutId: getCheckoutId(),
|
||||
checkoutId,
|
||||
lineItems: [
|
||||
{
|
||||
id: itemId,
|
||||
variantId: item.variantId,
|
||||
quantity: item.quantity,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
return checkoutToCart(checkoutLineItemsUpdate)
|
||||
return checkoutToCart(checkoutLinesUpdate)
|
||||
},
|
||||
useHook: ({
|
||||
fetch,
|
||||
|
@ -1,19 +1,19 @@
|
||||
import { checkoutDetailsFragment } from '../queries/get-checkout-query'
|
||||
|
||||
const checkoutLineItemRemoveMutation = /* GraphQL */ `
|
||||
mutation checkoutLineItemRemove($checkoutId: ID!, $lineItemIds: [ID!]!) {
|
||||
checkoutLineItemsRemove(
|
||||
mutation checkoutLineItemRemove($checkoutId: ID!, $lineId: ID!) {
|
||||
checkoutLineDelete(
|
||||
checkoutId: $checkoutId
|
||||
lineItemIds: $lineItemIds
|
||||
lineId: $lineId
|
||||
) {
|
||||
checkoutUserErrors {
|
||||
errors {
|
||||
code
|
||||
field
|
||||
message
|
||||
}
|
||||
# checkout {
|
||||
# ${checkoutDetailsFragment}
|
||||
# }
|
||||
checkout {
|
||||
${checkoutDetailsFragment}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { checkoutDetailsFragment } from '../queries/get-checkout-query'
|
||||
|
||||
const checkoutLineItemUpdateMutation = /* GraphQL */ `
|
||||
mutation checkoutLineItemUpdate($checkoutId: ID!, $lineItems: [CheckoutLineItemUpdateInput!]!) {
|
||||
checkoutLinesUpdate(checkoutId: $checkoutId, lineItems: $lineItems) {
|
||||
mutation checkoutLineItemUpdate($checkoutId: ID!, $lineItems: [CheckoutLineInput!]!) {
|
||||
checkoutLinesUpdate(checkoutId: $checkoutId, lines: $lineItems) {
|
||||
errors {
|
||||
code
|
||||
field
|
||||
|
Loading…
x
Reference in New Issue
Block a user