Metaobject Input With Variant Data Type Only Returns GID

Solved

Metaobject Input With Variant Data Type Only Returns GID

switchbladecomb
Shopify Partner
4 1 1

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 -%}

  <img
    class="content-img"
    src="{{ content_media_src }}"
    alt="{{ content_media_alt_text }}"
    width="{{ img_width }}"
    height="{{ img_width }}"
  >
{%- 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!

Accepted Solution (1)

switchbladecomb
Shopify Partner
4 1 1

This is an accepted solution.

Soooooo egg on my face. It turns out I was seeing this behavior because I hadn't noticed that the variant I was randomly selecting in during my testing belonged to a product that had actually been archived. So, as one might expect, if the variant you're attempting to get via liquid is archived it'll return the gid but nothing else.

View solution in original post

Reply 1 (1)

switchbladecomb
Shopify Partner
4 1 1

This is an accepted solution.

Soooooo egg on my face. It turns out I was seeing this behavior because I hadn't noticed that the variant I was randomly selecting in during my testing belonged to a product that had actually been archived. So, as one might expect, if the variant you're attempting to get via liquid is archived it'll return the gid but nothing else.