storefront-api-examples
storefront-api-examples copied to clipboard
Wrong response body when adding cart item to cart
When creating a cart with a product, which has an automatic discount applied like "Buy 3(n) and get 10% off", the (n+1) product added is not added to the cost of the line item.
Creating cart mutation
mutation { cartCreate( input: {lines: {merchandiseId: "gid://shopify/ProductVariant/44134907969855", quantity: 1}, buyerIdentity: {countryCode: DE, deliveryAddressPreferences: {deliveryAddress: {firstName: "Max", lastName: "Mustermann", country: "Germany", city: "Musterstadt", zip: "83772", address1: "Musterstrasse 1"}}}} ) { userErrors { message } cart { checkoutUrl id cost { totalTaxAmount { amount } totalAmount { amount } subtotalAmount { amount } } lines(first: 1) { edges { node { quantity id sellingPlanAllocation { priceAdjustments { price { amount } } } merchandise { ... on ProductVariant { image { url } title id price { amount } sellingPlanAllocations(first: 1) { edges { node { priceAdjustments { price { amount } } } } } } } } } } } } }
Mutation to add a single product
mutation { cartLinesAdd( cartId: "gid://shopify/Cart/c1-df9ac8e71b99a136405e930b4d60e44f" lines: {merchandiseId: "gid://shopify/ProductVariant/44134907969855", quantity: 1} ) { userErrors { message } cart { checkoutUrl id cost { subtotalAmount { amount } totalAmount { amount } } lines(first: 30) { edges { node { quantity id merchandise { ... on ProductVariant { image { url } title id price { amount } } } sellingPlanAllocation { sellingPlan { id } priceAdjustments { price { amount } } } cost { totalAmount { amount } amountPerQuantity { amount } compareAtAmountPerQuantity { amount } subtotalAmount { amount } } discountAllocations { discountedAmount { amount } } } } } } } }
Example response adding 6 items of a product with "Buy 5 and get 20% off"