Product metafield dynamic content not working on theme 2.0

Solved
Leocxy
Shopify Partner
7 1 1

For theme 2.0, you can use product/variant metafield as dynamic content.
We build an upsell function based on this feature. But it bounces back and forth between working and not working.

Here is the setting from the `product-template` section

 

 

...
{% schema %}
{
  "name": "Product",
  "class": "shopify-section--product-template has-sidebar-option",
  "settings": [
    {
      "type": "header",
      "content": "Upsell"
    },
    {
      "type": "checkbox",
      "label": "Show debug information for upsell",
      "info": "Information does not show on the frontend",
      "id": "show_upsell_debug",
      "default": false
    },
    {
      "type": "collection",
      "id": "upsell_collection",
      "label": "Upsell collection"
    },
...
{% endschema %}

 

 


Here is some setting from `product.json`

 

 

{
  "sections": {
    "main": {
      "type": "product-template",
      ...
      "settings": {
        "show_upsell_debug": false,
        "upsell_collection": "{{ product.metafields.upsell.collection.value }}",
        "upsell_add_button_text": "",
        "upsell_product_heading": "Add a  bulb for your {{ product.title }}",
        "upsell_product_content": "<p>The {{ product.title }} does not come with a bulb, so we’ve put together our favourite options that are compatible with this product. If you’d like more options, click the button below to view our entire bulb collection. <\/p>{{ product.metafields.content.bulbs_info | metafield_tag }}",
        "upsell_button_text": "",
        "product_thumbs": true,
        "gallery_arrows": true,
        "enable_product_lightbox": true,
        "activate_zoom": false,
...}},
 "order": [
    "main"]
}

 

 


In the `product-template` section, we try to detect the setting for upsell collection and render the JS.

 

 

{%- liquid
  if section.settings.upsell_collection
    render 'product-upsell-modal', section: section
  endif
  if section.settings.upsell_collection
    echo 'yes'
  else
    echo 'no'
  endif

  echo product.metafields.upsell.collection
-%}

 

 



Sometime echo `no` but we can see the collection gid next to it.

Does any one know why and how to fix it?

Accepted Solution (1)
Leocxy
Shopify Partner
7 1 1

This is an accepted solution.

Issue found. The are multiple JSON templates, and the products are associated with different JSON template, some of the JSON template does not set the upsell collection. That caused the issue.

View solution in original post

Reply 1 (1)
Leocxy
Shopify Partner
7 1 1

This is an accepted solution.

Issue found. The are multiple JSON templates, and the products are associated with different JSON template, some of the JSON template does not set the upsell collection. That caused the issue.