[Shopify]コレクションから上限50商品の制限なく、全ての商品を取得する方法

[Shopify]コレクションから上限50商品の制限なく、全ての商品を取得する方法

This time we will show you how to display products in a collection without limitation. By default, the maximum number of products that can be retrieved from a collection is actually 50.

Therefore, as the number of products increases, it is not possible to display them on a single page, for example, by creating pagination. However, by using the method described in this article, the 50-product limit can be eliminated and any number of products can be loaded.

This method is not often used in stores with a small number of products, but in large stores with a large number of products, this is a barrier that is frequently faced, so it is often used!

How to display products in a collection

The first method is simply to get the title of the product in the collection.

{% for product in collection.products %}
{{ product.title
}}{% endfor %}

This is fine for collection pages, but if you try to retrieve products by specifying a collection on other pages, you will get the following results. (where collection_url is the handle name of the collection you specify)

{% for product in collections[collection_url].products %}
  {{ product.title }}
{% endfor %}

If there are less than 50 products to be retrieved from the collection, this method is fine.

Default limit of 50 products in a collection

We will show you how to eliminate the 50-product limit next, but first, let us explain how the 50-product limit works.

In fact, the simple method of retrieving products from a collection, which we have just described, is the same as the following

{% for product in collection.products %}
  {{ product.title }}
{% endfor %}

but this part is actually


{%
paginate collection.products by 50 %}
{% for product in collection.products %}
{{ product.title }}
{% endfor
%}{% endpaginate %}



The hidden pagination is called!

The pagination is as shown below, and the above code would display 50 products per page.

pagination とは

In other words, the existence of this pagination itself is the cause of the "50-product limit.

How to eliminate the "50-product limit

Based on the previous explanations, here is how to eliminate the upper limit for acquiring products in a collection.

{% paginate collection.products by 1000 %}
  {% for product in collection.products %}
    {{ product.title }}
  {% endfor
%}{% endpaginate %}

Changed to "1000" in pagination.

Now we have the first 1000 products from the collection. For example, if the total number of products is less than 1000, all products can be retrieved using the above method.

Even if there are 1500 products in the collection, we can change the pagination to "10000" to remove the limit and retrieve all the products.

How to retrieve all products from a [Shopify] collection with no limit of 50 products.

This is how to break through the 50-product limit when retrieving products from a collection.

When we first implemented this, we thought it was normal to be able to retrieve more than 50 products, so we wondered why some products could not be retrieved. I started by investigating why some products could not be acquired, which consumed quite a bit of time.

Even if you don't actually face a problem, it may be useful in the future to keep in mind that there is an upper limit.

Thank you for reading to the end. Have a good day!

Contact form

新規ストア構築、開発などのお仕事の依頼・無料相談はこちら