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?