timd
August 25, 2021, 5:55am
1
I’ve set up a Product Variant reference metafield but when I try to use the metafield:
{{ product.metafields.bundle.product_1 }}
the output value is a GraphQL ID string:
gid://shopify/ProductVariant/517811666963
If I try to create a variant object from the metafield to access variant its attributes like id, title, product etc it doesn’t output any data:
{%- assign variant = product.metafields.bundle.product_1 -%}
{{ variant.id }}
I’m guessing this is because the metafield is a string rather than an object. So how would I actually use a variant metafield to access the variant object’s attribute?
timd
August 26, 2021, 3:55am
2
Alternatively, is there any way to assign a variant from a variant ID similar to the all_product function eg
Instead of:
{% assign product = all_products[product-handle] %}
Something like:
{% assign variantId = product.metafields.bundle.product_1 | replace: ‘gid://shopify/ProductVariant/’‘,’’
{% assign variant = all_variants[variantId] %}
{{ variant.title }}
Or is there a way to use GraphQL objects with Liquid?
timd
August 26, 2021, 4:06am
3
I managed to figure this out, you just need to append .value to the end of the metafied:
{{ product.metafields.bundle.product_1**.value** }}
kmart
September 10, 2023, 2:16am
4
I’m having the same issue, only getting the gid, however, adding .value did not work for me. Do you think it could be a theme issue? example
{{product.metafields.custom.product_1.value.title}}
this did not produce any output
but this
{{product.metafields.custom.product_1}}
produces
gid://shopify/Product/xxxxxxxxxxxx
timd
September 10, 2023, 7:28pm
5
Have you tried: {{product.metafields.custom.product_1.value}}
kmart
September 10, 2023, 10:11pm
6
Hi Timd,
Thanks! I solved the issue. The product wasn’t published to any sales channels (especially the store one). After that it worked.