Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Wrong response body (Cart API) when adding cart item to cart

Wrong response body (Cart API) when adding cart item to cart

Jujuba
Shopify Partner
23 0 6

When creating a cart (via API) 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 with product X

 

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
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Adding a single product X to the cart

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 X with has a automatic discount applied "Buy 5 and get 20% off".

As you can see, the cost of the 6th item is not added to the cost of the line item. The quantity is added.

Bildschirm­foto 2023-07-11 um 23.07.15.png

Replies 0 (0)