Correct me if I’m wrong, but there is still no way in liquid to get all of the variants?
The instructions and new liquid APIs seem to only support selecting specific variants out of the full set.
My app has to list all variants for Google SEO purposes. The old way to iterate over product.variants sounds like it will only ever output 250.
We can’t “eliminate overfetching or defer loading variant information” because
We are required to list all of them, so we are not overfetching
We cannot defer because search engines (e.g. Google) require all variant data on page load when the HTML is rendered without any interaction events
Based on this document, liquid cannot support listing any variants beyond 250. That means merchants will not be able to qualify for search enhancements, Merchant Center, or other advertisements. I’m shocked that this use case was overlooked.
Yes, it seems like pagination can work. I would have expected to see pagination mentioned in the docs for high variants as a solution, so that’s great.
However, I think the pagination docs are wrong, or the system actually supports a higher page_size than 50 as documented.
My dev store has 560 variants. The following code correctly returns all 560 at once.
{% paginate product.variants by 2049 %}
{% for variant in product.variants %}
{% assign prod_variant_count = prod_variant_count | plus: 1 %}
{{ variant.id | json }}
{% endfor %}
{% endpaginate %}
Total variants - {{ prod_variant_count }}
This works by making the page_size be large enough to get all the variants. The docs for pagination says it only supports up to 50. Setting page_size to 50 only returns 50 (probably just the first page).
Thanks for getting back to me. Glad pagination will work. I’ll look in to see what is expected here so we can get clarification on the proper supported amount.
I’m not sure if the page size can support a higher number than 50 or what the upper limit is. If this higher page_number is not official, will Shopify revert it later? I want to make sure it’s safe for production.
My product has 1386 variants. I’ve adjusted the page_size to 2049. But it can only return the first 1,000 variants. Therefore, this liquid hack cannot return all variants
Out of curiosity, and to help with a discussion we are having internally: what is a/the scenario is which a merchant has a valid use case for 100+ variants?
@Jacco
My use case is to create a bundle builder page where customers can select any particular number of variants from a collection and get a discount. Let’s say there are 20 products in a collection. The user wants to show these products on a page, where customers can pick and mix.
It’s easy to get above 100 when you’re considering custom made products or colors. Yes, there could be an argument to find a break point where they can be products, but sometimes that causes more confusion because those products are on different product URLs.
For the average merchant, metafields are still a confusing concept and linking products with variants on different pages can be a lot to digest. A few come to mind:
sweatshirt in many different colors, patterns, and sizes vs a t-shirt or tank top
yarn colors on different types of yarn
cell phone cases in various styles with however many phone brands and versions
I suspect most merchants will be closer to 250 than 2048 but I can only presume Shopify is setting that number to be excessively high so they don’t have to revisit this in the future.
@Tim-Shopify can we use the paginate tag in prod, assuming it would return up to 1000? What do you suggest to us in this case since it is not documented like that?