Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
We have a metafield called market.metafields.custom.available_product_variants which contains a list of variants for particular international markets. and no matter what we try we seem unable to apply a filter to it to reduce the number of items returned to get under the Shopify 50 limit.
We can assign localization.market.metafields.custom.available_product_variants.value (using localization to get a specific market) as so:
{% assign selected_variants = localization.market.metafields.custom.available_product_variants.value %}
and then we can loop through the array using FOR to output:
{% for variant in selected_variants %}
<p>Market Variant ID: {{ variant.id }}</p>
<p>Market Variant Title: {{ variant.title }}</p>
<p>Market Variant Product ID: {{ variant.featured_image.product_id }}</p>
<p>Product ID: {{ product.id }}</p>
{% endfor %}
We're including the product.id in order to check that we can output that as well - and it outputs as expected
We've tried numerous different ways and followed the documentation https://shopify.dev/docs/api/liquid/filters/where but nothing seems to work, as soon as we try and add a where filter - it stops working.
i.e.
#1 -With quotes for property name and double quotes for the value
{% assign selected_variants = localization.market.metafields.custom.available_product_variants.value | where: 'featured_image.product_id', "product.id" %}
#2 - Without quotes for property name and double quotes for the value
{% assign selected_variants = localization.market.metafields.custom.available_product_variants.value | where: featured_image.product_id, "product.id" %}
#3 - With the full variant name, quotes for property name and double quotes for the value
{% assign selected_variants = localization.market.metafields.custom.available_product_variants.value | where: 'variant.featured_image.product_id', "product.id" %}
#4 -With the full variant name, without quotes for property name and double quotes for the value
{% assign selected_variants = localization.market.metafields.custom.available_product_variants.value | where: variant.featured_image.product_id, "product.id" %}
What are we doing wrong?
So we managed to get round this thanks to the suggestion at: https://stackoverflow.com/questions/26807967/overcome-limit-of-50-in-for-loop-in-shopify
Namely we increased the pagination like so:
{% assign selected_variants = localization.market.metafields.custom.available_product_variants.value %}
{% paginate selected_variants by 1000 %}
{% for variant in selected_variants %}
<p>Market Variant ID: {{ variant.id }}</p>
<p>Market Variant Title: {{ variant.title }}</p>
<p>Market Variant Product ID: {{ variant.featured_image.product_id }}</p>
<p>Product ID: {{ product.id }}</p>
{% endfor %}
{% endpaginate %}
To be honest though - I don't want to be doing this, I only want to return the available_product_variants that I need after filtering it by the product of the page that it's on. It'd be less to deal with and just nicer on Shopify's servers too.
If anyone has a suggestion for doing a where filter on the array that works - would love to hear what we need to do.
Thanks
Neil
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024