-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sync Variant meta fields to the the DB #99
Comments
Hi @zsavajji Thank you for your message. Currently the plugin is only syncing the product's meta fields and not currently syncing the variant meta fields. We can add this as a feature request and look to get it in a future version of the plugin to make this easier. For a solution for the moment you are still able to get this data, if you are doing this in a twig template you could do the following: {# Assuming you have already retrieved the product and set it on a `product` variable #}
<strong>{{ product.id }} - {{ product.title }}</strong>
<ul>
{% for variant in product.getVariants() %}
<li>
<div>{{ variant.title }}</div>
{% cache using key "shopify:variant:metafields:" ~ variant.id %}
{% set metafields = craft.shopify.api.getAll('Shopify\\Rest\\Admin2023_10\\Metafield', {
metafield: {
owner_id: variant.id,
owner_resource: 'variants',
}
}) %}
{% if metafields|length %}
{% for field in metafields %}
<div>{{ field.key }}: {{ field.value }}</div>
{% endfor %}
{% endif %}
{% endcache %}
</li>
{% endfor %}
</ul> Noted that because we are interacting with the Shopify API I have wrapped the call in a Hope this helps and please keep an eye on this issue to see any progress with the feature request. Thanks! |
Hi @nfourtythree, thank you for taking time to send me the Twig snippet, but it's not a viable solution for me since I'm working headless with the ElementAPI. I'm now working with my fork, if you could check out my PR for the next version it would be pretty awesome :) Thanks! |
We have just released versions In those versions we have added a couple of new settings that allow you to control the syncing of meta fields for both products and variants. The settings can be added to your For variants setting Thanks! |
Hi, I am using the addon on a new project on Craft5, but I'm stuck on a (seemingly) simple problem.
Is there no way to get the values of the metafields stored on variants? I'm trying to get color custom codes on items but i'm unable to get such information from Shopify, is this the correct behavior?
Thanks
Additional info
The text was updated successfully, but these errors were encountered: