Sort by Quantity

Tourist
11 0 2

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.

 

Thanks

0 Likes
Highlighted
Excursionist
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.

0 Likes