Product metafield of type ProductVariant not listed in dynamic sources in the theme editor

Hey fellow devs,

Please allow me to briefly introduce the context in which I’m working. Then I’ll ask my question. At first glance, it may seem like a lot, but with my careful explanation and accompanying screenshots, I think you’ll find it very easy to follow. This may be a simple problem with a simple answer, but I’m new, so please bear with me.

Context:

I’m working through the Exploring and Extending Shopify’s Data Model course and there is a lab exercise where I’m supposed to create one metaobject and two metafields within the Product primitive in order to dynamically display some information about the model in the image on the product template within the theme editor.

[Screenshot showing final result removed due to 5 upload limit as a new Community user, but you can find it in the above referenced Shopify Academy course]

The exercise instructions say to use “Single line text” as the type for the “Model Size” metafield, but since we have the ability to create a “size” variant for these products, I thought it might be better to create the “Model Size” metafield with the ProductVariant type. This way, I can ensure consistency between the variant value and the metafield value.

My custom data:

Product using my custom data:

In order to display the metafield data on the product template, the instructions say to add a new “Collapsible Row” block to the product template (Dawn theme). I decided to use “Icon with text”, but for the sake of simplicity, I’m going to show a simple “Text” block. The problem I’m running into exists regardless of which block I choose.

Here’s My Problem: Where is Model Size?

As you can see in the above screenshot, I have the “Model Info”, which is a reference to a Metaobject, as an available dynamic source. However, I don’t have the other metafield, which is of type ProductVariant, available. If you look back at the screenshot above this one, you can see that there is definitely two metafields on the product (Model Size and Model Info). Again, they’re both references. “Model Size” references a ProductVariant and “Model Info” references a Metaobject (see first screenshot).

I tried to hardcode the value with object notation, but I didn’t know which properties to use. Trying something like {{product.metafields.model.size.value}} resulted in an error message.

I needed to know what “product.metafields.model.size.value” was returning. So I opened up the Shopify GraphiQL App and queried the product in question. As someone who is not too familiar with this API yet, I noticed something strange. The metafield that stores the reference to the metaobject doesn’t seem to store it as a reference, as indicated by the null value. Yet, the metafield that references the ProductVariant does seem to store it as a reference, as indicated by the returned __typename. This query result did not prove to be too helpful, but, I’m curious, why does it do this?

In summary, where is Model Size in the dynamic sources list and can someone please explain the discrepancy in the query results with respect to the reference field?

Hi James!

Great to see you’re learning how the custom data model works :slight_smile:

For why the metaobject isn’t setting reference, it’s possible that the metaobject definition is not configured for Storefront API access and you’re querying storefront:


For the model size showing up in the picker as a data source, since you chose to use a variant reference rather than single line text field it won’t work since variant reference is not supported as a data source type: Dynamic data sources

Have connected with the team who created this content for their recommendations too.

Hey Liam! Thanks for the quick reply (and for appropriately updating the tags :slightly_smiling_face:).

Two things:

  1. The Model Info metaobject definition is configured for Storefront API access. I believe that’s why I’m able to access it from the dynamic sources.

  2. Thank you for clarifying that we can’t access metafields of type ProductVariant in dynamic sources. My follow up question to that response is why not? It seems like a perfectly reasonable data point to be able to access in this situation. The referenced variant value is text based (e.g. “Extra Large”). The field works as expected on the admin side as indicated in my screenshot. Why isn’t it possible to surface that in a text field in the theme editor?

I appreciate that you yourself may not know the answer as to why it’s not possible in the current version of Shopify, but I propose that it should be possible. Even though I have no immediate need for this, I believe that since we have the ability to create a product metafield for a reference to a variant, such as Size, I expected, rightfully so, to be able to surface that data from a dynamic source, especially when, at the end of the day, it’s just a text value that I’m after. It’s simply a matter of the development principle Don’t Repeat Yourself. What if, in haste, a user types “Wxtra Large” or “XXL” when the correct value should have been “Extra Large”. By using a variant reference and being able to surface that data in the theme editor as a dynamic source, we can minimize human error. Would you agree or am I overlooking something?

Hi again James - agree with your points here. Let me connect with our custom data team on these!