I keep app’s data in App-data metafields but apparently it is not possible to access them in Checkout UI extension. Could you guys confirm that it is not possible, or i’m doing something wrong.
So it appears that the unfortunately named AppMetafields is actually not referring to app metafields, but metafields on the relevant Shop, Customer, Product, or Variant.
I’m wondering if it’s possible to use the Storefront API to fetch the metafields on the Shop but using reserved prefixes to protect the metafields from being changed by other apps.
@DavidT Never tried. So you need to have access to the same global metafields from your app, checkout ui extension and Storefront API? Let me know if you find a solution for it.
Could you advise how you did this?
I’m having trouble getting anything but undefined when using the useAppMetafields react hook. I’m unsure of how to format the filters.
Thanks so much!
I think the configuration in the toml file should be [[extensions.metafields]] or [[extensions.targeting-metafields]], but I have not yet found a way to make it work.
Did you succeed in getting it to work?
Yeah I understand that part. But how do you add the data to the metafields from an embedded app, for example if you want the merchant to make configurations that will be used in the checkout ui extension?
I am not sure I understand your question, but in general you can add UI to the embedded app that allows the merchant to configure different parameters. You can set those settings in metafields with the graphql mutation metafieldsset c.f. https://shopify.dev/docs/api/admin-graphql/2024-01/mutations/metafieldsset.
No you are using “metafieldDefinitionCreate” - this just creates a metafield definition for you to see in the admin under Settings → Custom data, but it does not set a value in the metafield. If you want to set a value in the metafield, you should use the graphql mutation metafieldsset c.f. https://shopify.dev/docs/api/admin-graphql/2024-01/mutations/metafieldsset.
Ensure that data is actually set - I don’t know whether you check the response from metafieldsSet to determine whether an error occurred.
But you can go into the admin → Settings → Custom data → Shop and manually set a value in you metafield and then test whether you can access the value in the UI extension
Sorry I’m a bit out of practice with checkout extensions, as I haven’t looked at them for about 6 months.
If I’m understanding the issue you’re having (which I’m not sure I am haha), I think it might be helpful to look at Nicks answer to this post I made when I was having issues.