Is this a viable solution to list both stocked products and continue selling when out of stock prods

LostPer
Excursionist
31 1 3

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 %}

 

 

 

 

 

0 Likes
LostPer
Excursionist
31 1 3

Just found a big issue

Pagination. It loads all products (ofc) into the list and then I "hide" the sold out, so I can end up with 50 products on one page and 12 on next. 
Suggestions?

0 Likes