Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overcome limit of 50 in for loop in shopify

I have paginated a product list over a limit of 50 to fit in the whole page (index.liquid). But the if condition within for loop doesn't apply over whole paginated items as for loop is limited to 50 items. Any help would be appreciated.

{% paginate collections.all.products by 1000 %}
    {% for product in collections.all.products %}
      {% if product.metafields.spr.reviews %}
        {{ product.metafields.spr.reviews }}
      {% endif %}
    {% endfor %}
{% endpaginate %}
like image 928
optimus Avatar asked Nov 07 '14 18:11

optimus


2 Answers

The 50 items limit per page should be correct and it is documented. Except for the fact that... It is not. Actually, you can circumvent that limit in Shopify by establishing a higher limit of up to 1000 items per page. Just being redundant, here is a sample code:

{% paginate mycollection.products by 250 %}
  {% for product in mycollection.products %}
    {% include 'my-product-template' %}
  {% endfor %}
{% endpaginate %}

Also answered here.

like image 52
Marcos Buarque Avatar answered Oct 05 '22 03:10

Marcos Buarque


No, you cannot overcome it, You can query up to 50 product per page, Shopify won't allow more than 50 products, in order to maintain server load balance.

quote from shopify documentation : http://docs.shopify.com/manual/configuration/store-customization/page-specific/collections/add-view-all-to-collection-pages

Don't ever paginate a collection by more than 50, that's how many products maximum you should query per page. Be respectful of Shopify's app servers. If you are not using any paginate tags, pagination does kick in behind the scene and you will only receive the first 50 products in said collection.

like image 25
Sark Avatar answered Oct 05 '22 01:10

Sark