Solved

Metaobject Product Field - how to access the data?

ginacostanzo
Shopify Partner
13 2 6

Hi, I've been working on implementing a new metaobject in my company's Shopify store called Lessons. I'm able to access the lesson.title, lesson.description,etc. However, I cannot access the featured products. In my metaobject I set up a field called featured products and set it as a product data type (list option). I've tried so many different formats of dot notation to access the products for a lesson and nothing works. Anyone figured this out that can offer some advice?

{% for product in metaobject.featured_products %} <div>{{ product.title}}</div> {% endfor %}

outputs nothing
.

Also tried accessing via the GIDs that are returned by looping through all_products and keeping the ones with matching IDs, but also displays nothing. 

Accepted Solution (1)

ginacostanzo
Shopify Partner
13 2 6

This is an accepted solution.

Okay update - I finally found a youtube video https://www.youtube.com/watch?v=eQHt2xil3Js that explains referencing products and objects in code and how the notation differs from something like simple text. Very informative video! 

View solution in original post

Replies 3 (3)

Made4uo-Ribe
Shopify Partner
6430 1542 1911

Hi @ginacostanzo 

 

You need to call shop.metaobjects. Try the code below.  You can read more about metaobjects here

{% assign metaobject_products = shop.metaobjects['featured_products '].values %}

{% for product in metaobject_products %}
{{ product.title }}
{% endfor %}

 Please don't forget to Like and Mark Solution to the post that helped you. Thanks!

If this fixed your issue Likes and Accept as Solution is highly appreciated. Coffee tips fuels my dedication.
Get EXPERIENCED Shopify developers at affordable rates—visit Made4Uo.com for quick quote!
Do not lost your Shopify store! Get FREE trial with ✔️ Rewind Backup: Automatic, reliable, stress-free.
ginacostanzo
Shopify Partner
13 2 6

Thanks for your reply. I'm calling metaobject directly because this is within a metaobject template. So my overall metaobject is called lessons and then within that one of the metafields is featured_products. 

I created a metafield template so it will generate a page for every metaobject entry (every lesson), so that is why i'm writing just metaobject and not shop.metaobjects.

When I write metaobject.title it works. 

If I write metaobject.featured_products I get back an array of gids, but haven't been able to use that in any way. And if I try to loop through the featured_products to display properties of each product, it's blank.

ginacostanzo
Shopify Partner
13 2 6

This is an accepted solution.

Okay update - I finally found a youtube video https://www.youtube.com/watch?v=eQHt2xil3Js that explains referencing products and objects in code and how the notation differs from something like simple text. Very informative video!