Storefront API ProductSortKeys add PRICE

Storefront API ProductSortKeys add PRICE

Joshua_Johnson1
Visitor
2 0 0

I'm working on a custom store front for my shopify site and I'm using the Storefront API with GraphQL. I have a products page but I'm not able to sort by Price currently from the server.

https://help.shopify.com/en/api/custom-storefronts/storefront-api/reference/enum/productsortkeys

PRICE sort key seems like it should be the most commonly used sort key. Any change this can get added?

Replies 3 (3)

Alex
Shopify Staff
1561 81 342

Prices are not serialized on Product resources, so it would not make sense to provide the SortKey here. That said, the SortKey is not presently available on ProductVariants. It looks like price is not an indexed property, meaning it's a much less performant query.

That said, feedback passed along. I can see why you'd want to do this. Thanks for posting!

Alex | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Joshua_Johnson1
Visitor
2 0 0

Thanks for the response, Alex. I'm a developer myself so I understand the constraint. Any workarounds you would recommend for the time being? I don't want to implement a sort on the client side because it would mess up pagination as I pull more products and I don't want to pull every product for obvious performance reasons. Kind of stuck here. There is sorting by price on collectionsByHandle but there I don't have the ability to query/filter. I want the best of both of those haha.

Alex
Shopify Staff
1561 81 342

Hey Josh,

There aren't any workarounds I'm aware of for the moment. I wonder if it would make sense for you to perform filtration on the liquid level? https://help.shopify.com/en/themes/liquid/filters/array-filters#sort

You could maybe make use of an application proxy in order to leverage the liquid engine from your back end if necessary, collect the output from there, and feed it into wherever you need it? Just a thought.

Cheers.

Alex | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog