The new `find` filter doesn't work as expected on paginated arrays
By default, product.variants are limited to 250 variants. When you use the find filter on this array, it only searches within those first 250 variants instead of all variants of the product.
For example:
assign variant = product.variants | find: 'id', variant_id
echo variant
This code will only work if the variant_id is within the first 250 variants.
Is this a known limitation?
It can't search what isn't loaded. You would have to do something like:
{% liquid
paginate product.variants by 9999 %}
for item in product.variants
assign variant = product.variants | find: 'id', variant_id
echo variant
@andershagbard I believe pagination is limited to 1000 items, so it won't load more than 1000 variants.
This is still expected behavior
It would be very helpful if array filters worked on entire arrays and not just the current page.
One use-case for this is getting variants with featured_media (product.variants | where: 'featured_media'). Currently there’s no clean way of getting variants past the 250th variant that have featured media.
I think even Shopify's own Horizon theme won't work with products with more than 250 variants: https://github.com/Shopify/horizon/blob/ec77746e6c926fa3b532c773ef8d00480ef9585a/snippets/product-card.liquid#L47-L53
If array filters has 250 limit, Shopify should document it. This makes array filters pretty useless against large array like collection.products, and yet, Shopify uses collection.products to demonstrate those filters.
Using the above screenshot as an example, why would any merchant want to sort the products in a collection by price, if it can only sort within the first 250 or 50 products from the original order?
For above filter, if that number 10 is changed to another number over 250, this will always return false, why is this not documented?
This is especially tricky and frustrated when you use filters like where or find or has as when it doesn't return anything you thought your collection doesn't have a matching product but in fact, it is only the Top 250 products has no matching product. How does it make any sense to anyone who is building theme using liquid?