Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
The line items returned by the Cart Storefront API are not sorted by newly-added first (as shown in the checkout page). In fact, there doesn't seem to be any order at all.
How is one supposed to effectively retrieve the ID of line items added using the `cartLinesAdd` mutaiton, if the lines are not sorted in any predictable fashion.
One might be tempted to use a query such as the following to retrieve the last line item which was added to the cart, but since lines are returned in a random order, it will return one of the lines items in the cart, but not necessarily the last.
mutation cartLinesAdd($cartId: ID!, $lines: [CartLineInput!]!) {
cartLinesAdd(cartId: $cartId, lines: $lines) {
cart {
lines(first: 1) {
edges {
node {
id
}
}
}
}
}
}
This was first reported in 2018.
https://github.com/Shopify/js-buy-sdk/issues/501
Other reports include:
https://community.shopify.com/c/shopify-apis-and-sdks/storefront-api-issue-with-checkoutlineitemsrep...
https://github.com/Shopify/storefront-api-feedback/discussions/32
https://github.com/Shopify/storefront-api-feedback/discussions/15#discussioncomment-1259112
Am I missing something? Any advice is appreciated.
How does a corporate behemoth like Shopify leave an issue like this unaddressed for over 3 years?
It's been a while since this post and wonder if there has been any updates on this. I'm interested.