Hello!
I’m attempting to get variant information from an input field within a metaobject definition (Note: not a metafield definition). The data type for the input is Variant which presents a variant picker to the user. Everything up to that point works as expected. I also have the same setup for a Product input field. What’s odd to me is that I can easily access all of the information for the Product value that gets returned with code like this:
{%- for entry in shop.metaobjects.store_content_schedule['2024-04-10']['cart_drawer_content'].value -%}
{%- if entry.product != blank -%}
{%- assign content_media = entry.product.value.featured_image -%}
{%- endif -%}
{%- assign img_width = 240 -%}
{%- assign content_media_src=content_media | image_url: width: img_width -%}
{%- assign content_media_alt_text = content_media.alt -%}
{%- endfor -%}
As expected, this consistently yields an image with all of this information filled in. If I try to do the same thing with the Variant input field however, everything is blank. The only thing I’ve been able to successfully return from the Variant input was a gid by doing something like this:
{%- if entry.variant != blank -%}
{{ entry.variant }}
{%- endif -%}
All of the sane and wacky attempts below return absolutely nothing:
{%- if entry.variant != blank -%}
{{ entry.variant.id }}
{{ entry.variant.value }}
{{ entry.variant.value.id }}
{{ entry.variant.values.id }}
{{ entry.variant.id.value }}
{{ entry.variant.id.values }}
{{ entry.variant.value.id.value }}
{{ entry.variant.values.id.value }}
{{ entry.variant.value.id.values }}
{{ entry.variant.values.id.values }}
{{ entry.variant.value.id.values }}
{{ entry.variant.values.id.values }}
{{ entry.variant.value.id.values }}
{{ entry.variant.values.id.values }}
{%- endif -%}
I’ve checked the docs (metaobject, data types, variant object) and can’t seem to find an explanation as to why this might be. Does the Variant input also need a Product input for some reason? Meaning do I first need to grab a product using the Product input field and then using that information use the Variant input field to target that specific variant within the Product returned from the Product input?
Any help that can be offered would be greatly appreciated!