Storefront api cart cost is incorrect

Topic summary

Storefront API line item costs are incorrect when discounts are applied, while overall cart totals and checkout totals remain correct. The mismatch occurs specifically in cart line cost.totalAmount and cost.subtotalAmount.

Details: A GraphQL cart query (with cost and discountAllocations fields) shows line amounts that should equal price × quantity (e.g., 169 × 2 = 338) but do not when an automatic discount is active. The checkoutUrl leads to a checkout where line costs and totals are correct.

Scope: Reported with automatic product discounts, and also with a non-automatic “buy X get Y” discount code after updating line quantities via the API. A similar issue is seen when a manual currency conversion rate is set.

Technical notes: “Storefront API” is Shopify’s API for custom storefronts; “buy X get Y” applies free/discounted items; “discountAllocations” are per-line discount breakdowns. The provided code snippet and screenshots are central evidence.

Outcome: No workaround or solution is provided. The issue remains open with users seeking answers.

Summarized with AI on January 21. AI used: gpt-5.

Hey, we are using the shopify storefront api’s to manage customer’s shopping, And there is a critical issue for the cost when automatic discount is applied.

query cart($cart_id: ID!, $first: Int) @inContext(language: EN, country: HK) {
    cart(id: $cart_id) {
        totalQuantity
        checkoutUrl
        discountCodes {
            applicable
            code
        }
        discountAllocations {
            ... on CartAutomaticDiscountAllocation {
                title
                discountedAmount {
                    amount
                    currencyCode
                }
            }
        }
        cost {
            totalAmount {
                amount
                currencyCode
            }
            subtotalAmount {
                amount
                currencyCode
            }
            totalTaxAmount {
                amount
                currencyCode
            }
            totalDutyAmount {
                amount
                currencyCode
            }
        }
        lines(first: $first) {
            edges {
                node {
                    id
                    quantity
                    
                    cost {
                        totalAmount {
                            amount
                            currencyCode
                        }
                        subtotalAmount {
                            amount
                            currencyCode
                        }
                    }
                    discountAllocations {
                        ... on CartAutomaticDiscountAllocation {
                            title
                            discountedAmount {
                                amount
                                currencyCode
                            }
                        }
                    }
                    merchandise {
                        ... on ProductVariant {
                            id
                            product {
                                id
                                title
                                featuredImage {
                                    url
                                }
                                priceRange {
                                    maxVariantPrice {
                                        amount
                                        currencyCode
                                    }
                                    minVariantPrice {
                                        amount
                                        currencyCode
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

in the response, the lines returned here is not correct, the totalAmount and ‘subtotalAmount’ should be $169*2=$338.

We have an active automatic discount in our shopify store, and the issue only happens when this rule is applied to the cart.

But in the checkout link , everything is correct:

1 Like

I’m seeing this same issue when updating cart line quantities via the Storefront API with a (non-automatic) buy X get Y discount code. The overall cart cost is correct, but line item costs are incorrect. Have you found any answers?

Same here. When adding automatic product discount the cart total amount is correct, the line cost is incorrect.

Anybody knows a workaround?

I see a similar/same problem when we have a manual conversion rate set for a certain currency.