Any image attached only to a variant that is not among the first 250 variants of the product won’t get the attached_to_variant? == true.
Reproduction steps
Create a high variant product with more than 250 variants. Add two images to that product. Attach one of the image to the first variant and the second to a variant that is not among the first 250 variants of the product. Now if you loop the product.images in liquid only the first image will be marked as attached_to_variant? == true. Both should return true.
Additional info
We use the attached_to_variant? boolean value to group the variant related images in our theme. So that merchant can for example show image/s related to a certain color. Now this won’t work on high variant products. The new APIs for high variant products won’t solve this problem either. So we are really looking forward for a fix in the image LIQUID object from Shopify side.
Hey @Joonas, we have had fairly comprehensive discussions around over 250 variants in liquid in the thread here. Can you look that over and see if this gives more clarity on how to approach this?
Thanks for the quick response. However the thread you’ve forwarded has very little to offer on this problem:
The returned values of product.images attached_to_variant? will remain the same, no matter on what variant URL you’ll keep calling it. Since we are using a product level object. We also consider that the logic would get unnecessarily complex to use APIs to fetch relatively simple information about the product images.
We can make a theme level workaround for this problem. Not ideal but doable that requires the merchant to mark the images that are attached to any variant manually. So essentially re-implementing attached_to_variant? manually to product images since the Shopify backend can’t handle this on high variant products.
We know that this is quite a edge case issue, so we understand if you are unable to or unwilling to change the logic on Shopify’s backend. I would still recommend that you would add some sort of a warning or note to the Liquid Dev Docs to highlight what product level information is missing or uncompleted on high variant products.
Hey @Joonas, I dug into this more and found that this is a known issue on our side. attached_to_variant? on product.images only resolves variant associations for the first 250 variants, so anything attached to variant #251+ incorrectly returns false. We’re tracking it internally, though I don’t have a timeline for a fix.
The closest alternative right now is using variant.featured_media on the selected variant instead of filtering product.images by attached_to_variant?. The Support product variants guide walks through how to use product.selected_or_first_available_variant with featured_media to display the right media for the active variant. The Support product media guide covers rendering with product.media as well.
One thing to be aware of though is that variant.featured_media only gives you media for the currently selected variant. For that use case, the merchant-tagging workaround you described should work. Alternatively, you could test using list.file_referencemetafields on your variants to store the associated images per variant.