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.

[Storefront API] Cart/Checkout line items order is non-deterministic

[Storefront API] Cart/Checkout line items order is non-deterministic

pawlka
Visitor
2 0 4

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?

 

Reply 1 (1)

NicoSpoke
Shopify Partner
23 0 16

It's been a while since this post and wonder if there has been any updates on this. I'm interested.

Building digital interfaces for Shopify Stores