Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
I have the following UI where I want to increment o decrement the quantity of a product and update the cart immediately.
I am using the following mutation:
...
const handleUpdateExistingCartLines =() =>
...
const updateCartMutation = gql`
${CART_COMMON_FIELDS}
mutation cartLinesUpdate($cartId: ID!, $lines: [CartLineInput!]!) {
cartLinesUpdate(cartId: $cartId, lines: $lines) {
cart {
...cartProducts
}
}
}
`;
const variables = {
cartId,
lines: [
{
quantity: parseInt(quantity),
id: mainId,
},
],
};
try {
return await graphQLClient.request(updateCartMutation, variables);
} catch (error: any) {
throw new Error(error);
}
}
I than use the above mutation by invoking the following function:
Solved! Go to the solution
This is an accepted solution.
Hi Alexander,
This sounds like a variable mismatch in your code - and looks slightly similar to this GitHub issue. If you follow a similar approach to what is advised there, can you resolve this?
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
This is an accepted solution.
Hi Alexander,
This sounds like a variable mismatch in your code - and looks slightly similar to this GitHub issue. If you follow a similar approach to what is advised there, can you resolve this?
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog