I need to list products in my collections that is either in stock with "track quanity" and products with no stock but with "continue selling when out of stock"
I came up with the solution to exclude the inventory > 0 in collections (but that will list all products that is sold out also)
and instead add this code to my collection template. My question, is this an acceptable solution or should I solve it any other way? I'm worried for speed issues or future issues I'm not seeing.
{% if collection.products_count > 0 %}
{% for product in collection.products %}
{% assign first_inventory = product.selected_or_first_available_variant.inventory_quantity %}
{% if product.selected_or_first_available_variant.inventory_policy == "continue" or first_inventory > 0 %}
<div class="grid-item col-6 {{ grid_item_width }}">
{% include 'product-grid-item' %}
</div>
{% endif %}
{% endfor %}
User | Count |
---|---|
11 | |
7 | |
7 | |
7 | |
7 |