Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi,
Is there a way to implement custom sorting rules for products within a collection using the Storefront API? For instance, I'd like to maintain the existing sorting options (provided by GraphQL/ProductCollectionSortKeys) but also consider product tags. If a product has the tag 'Sold Out', I want to move it to the end of the list. Can I achieve this without modifying the existing sorting and pagination provided by Shopify GraphQL?
Ultimately, my goal is to create a more complex and dynamic sorting system, allowing me to sort products based on various conditions. However, for now, this question is sufficient.
Hi @luxehouze_dev 👋, short answer no.
Longer, sort the actual collection, if it's an "smart" collection create a copied manual collection with manual sorting AND this including the responsibility of keeping products in the source collect up to date in the target collect.
Otherwise it's loading the entire collect into a frontend and making the users browser do the work.
For binary operations, has tag | does not have tag, get the filtered-query then get the main query and prune off anything that's in the filter-query that should then be put at the end.
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Hi Paul, thanks for the answer. It seems like your solution is quite similar to what I had in mind. Initially, we fetch all products from the collection with existing filters, then at the code level, we manually sort all products with the 'Sold Out' tag to the end and implement manual pagination. However, I'm wondering if there's a more efficient workaround or alternative approach.
Exchange multiple network requests to avoid frontend sorting.
Either through the collection product connection use the filters for either available status for the head of the data; then tags, or variantMetafield for those only with a "Sold Out" value; or inverse "In stock" value.
Or in products query those also with/without a tag/tag_not and a specific collection name as a tag also.
products query tag_not query filter , doing a tag_not query then the tag query to join the data #1 that omits the "Sold Out" "collection name" tagged items with the data #2 that is ONLY the "Sold Out" "collection name" tagged items.
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Discover how to increase customer engagement on your store with articles from Shopify A...
By Jacqui Apr 23, 2025Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025