ensure products have at least one variant

This commit is contained in:
Greg Hoskin
2021-04-27 17:54:42 -05:00
parent a409c373c4
commit c6d06e60b6
6 changed files with 54 additions and 40 deletions

View File

@@ -24,13 +24,23 @@ export const handler: MutationHook<Cart, {}, CartItemBody> = {
message: 'The item quantity has to be a valid integer greater than 0',
})
}
const variables: {
product_id: string
variant_id?: string
checkoutId?: string
quantity?: number
} = {
checkoutId: getCheckoutId(),
product_id: item.productId,
quantity: item.quantity,
}
if (item.productId !== item.variantId) {
variables.variant_id = item.variantId
}
const response = await fetch<Mutation, MutationCheckoutLineItemsAddArgs>({
...options,
variables: {
checkoutId: getCheckoutId(),
product_id: item.productId,
quantity: item.quantity,
},
variables,
})
return checkoutToCart(response) as any