1

I'm trying to implement a sort order in my product listings so that all of the out of stock products are last.

I'm unsure how or if this is possible because the stock is set on the variants of a product and I'm listing the products.

The stock level would need to take into account the stock of all the products variants.

I know we have the ability to only fetch products that have stock with the criteria hasVariant: { hasStock: true }, but is there a way I can sort them using the .order() criteria?

2

Not possible at the moment, Craft would need to add better support for custom element sorting.

Can you please submit the request here so we can track it: https://github.com/craftcms/commerce/issues

This answer will be updated if there is a change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.