Sort by Quantity

11 0 3

Anybody know of any method or app that allows you to sort collection pages by amount of inventory?


We want to show products with the highest amount of stock first on the page.



15 0 6

This can't be done very easily unless none of your products have variants. You can sort by 'available':

{% assign products = collection.products | sort: 'available' %}
{% for product in products %}
  <h4>{{ product.title }}</h4>
{% endfor %}


But this is only whether all of your variants are out of stock or not. 


For each product you would need to check the inventory of 1 or more variants. Check out the Shopify product object, where you will find the product.variants property, there you can then check each variant's inventory. The easiest way to sort them would be to create a metafield for each product that holds the total inventory for the product, which you can then sort by that meta field value.

9 0 1

Yes, this app does it: 


It will need to use the manual/featured sort option to create it.  You can simply rename the manual/featured sort in Edit Theme Language.


One drawback is that they app makes this new sort to the default sort and you can not change that.  We only want it to be an option and not to override the default sorts set on the collections, so we had to delete the app.