Use availability of a referenced product in metaobject page template?

Solved

Use availability of a referenced product in metaobject page template?

bpaulette
Tourist
10 0 2

I'm pretty new to all of this, apologies if this is a dumb question.  

 

Let's say I've got a metaobject definition that includes a field of the "product" type, called "related_product".  On each entry, I select the related product.  On the page template for that metaobject, I want to display a button only if that referenced product is available.

 

In a custom liquid element, I'm finding that

{{ metaobject.related_product }}

kicks out the gid of the related product I selected on that entry.  Great, so it's seeing that product

 

But I was hoping to do something like 

 

{% if metaobject.related_product.available is "true" %}

Display button

{% endif %}

 

But can't seem to get anything like that to work.  Any way to make something like that work?

Accepted Solution (1)

tim
Shopify Partner
4481 532 1634

This is an accepted solution.

You need to use .value to get actual product object from the metafield reference:

https://shopify.dev/docs/api/liquid/objects/metafield 

 

{% if metaobject.related_product.value.available %}

Display button

{% endif %}

is "true" is not a thing in Liquid.

If my post is helpful, hit the thumb up button -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com

View solution in original post

Replies 4 (4)

Shadab_dev
Shopify Partner
1413 72 153

Why not use metafields for this? Just asking.

Not sure but May be using metafields you can get more than gid so other info of the product.

Buy me Coffee, if you feel i was helpful. Email Me here or WhatsApp me with this link for any help with shopify theme customizations or any project in web dev. If this is helpful, please Like and Accept the solution.

tim
Shopify Partner
4481 532 1634

This is an accepted solution.

You need to use .value to get actual product object from the metafield reference:

https://shopify.dev/docs/api/liquid/objects/metafield 

 

{% if metaobject.related_product.value.available %}

Display button

{% endif %}

is "true" is not a thing in Liquid.

If my post is helpful, hit the thumb up button -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com
bpaulette
Tourist
10 0 2

AHHHhhhh, thanks so much.  I had already tried using .value but I had put it after .available

tim
Shopify Partner
4481 532 1634

Basically, .value makes an object out of reference. 

So you use it on the metafield reference and then can use object properties.

If my post is helpful, hit the thumb up button -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com