Hi.
I am curious if you can get products Meta Fields within the ajax cart? For example I have a Metafield for a Short Name, and would like to include that after the title of the product in the cart.
Any help is much appreciated. Thanks!
Hi.
I am curious if you can get products Meta Fields within the ajax cart? For example I have a Metafield for a Short Name, and would like to include that after the title of the product in the cart.
Any help is much appreciated. Thanks!
You can, but the process will differ from theme to theme.
In a general sense, since metafields are not included in the cart.js response you’ll need to make your own alternate template that can return json, that also includes metafields.
Can you give any examples?
I’m using Admin ApI calls for managing my app.
How can I create alternate template
I have found only ajax-cart-template.liquid
{% comment %}
This snippet provides the default handlebars.js templates for
the ajax cart plugin. Use the raw liquid tags to keep the
handlebar.js template tags as available hooks.
{% endcomment %}
Didn’t find any template that return product params to cart.json
I’m using Brooklyn theme.
is there is any option to hide ajax cart by using Admin API ?
Thanks for checking this
The AJAX API is for the online storefront so I’m not sure what your plans are with the Admin API since that’s related to the data of the store.
In any case, here’s a simple alternate template example. You’ll need to add all the rest of the info you need into this.
{%- layout none -%}
{
"items":[
{%- for item in cart.items -%}
{
"someValue": {{ item.product.metafields.foo.bar | json }}
}{% unless forloop.last %},{% endunless %}
{%- endfor -%}
]
}
For further reading:
https://help.shopify.com/themes/customization/store/create-alternate-templates
{{#properties}}
{{#each this}}
{{#if this}}
{{@key}}: {{this}}
{{/if}}
{{/each}}
{{/properties}}