Answers.Body: <p>Not possible at the moment, Craft would need to add better support for custom element sorting.</p>
  
  <p>Can you please submit the request here so we can track it: <a href="https://github.com/craftcms/commerce/issues" rel="nofollow noreferrer">https://github.com/craftcms/commerce/issues</a></p>
  
  <p>This answer will be updated if there is a change.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-27T09:12:50.077Z
Answers.LastActivityDate: 2018-03-29T00:01:13.760Z
Answers.LastEditDate: 2018-03-29T00:01:13.760Z
Answers.UserDisplayName: Luke Holder
Body: <p>I'm trying to implement a sort order in my product listings so that all of the out of stock products are last.</p>
  
  <p>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. </p>
  
  <p>The stock level would need to take into account the stock of all the products variants.</p>
  
  <p>I know we have the ability to only fetch products that have stock with the criteria <code>hasVariant: { hasStock: true }</code>, but is there a way I can sort them using the <code>.order()</code> criteria?</p>
  
Tags: <plugin-craftcommerce><ordering>
Title: Ordering/sorting products by their variant stock level
ThreadText: # Ordering/sorting products by their variant stock level
  
  (Asked by: username_0 on 2017-01-03)
  
  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?
  
  **Tags:** plugin-craftcommerce, ordering
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-01-27. Score: 2 | Accepted answer
  
  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.
  
  
  ---
  
  