Shopify - 在静态部分块中使用产品类型,无法显示值

Shopify - Using product type in static section block, unable to display value

我有一个带有块的静态部分,允许商家从产品列表中进行选择。我的模块按预期在仪表板中工作,但我不知道如何显示每个产品的值。

这是我的模式的样子:

{
  "name": "New Arrivals",
  "max_blocks": 4,
  "blocks": [
    {
      "type": "new-arrival",
      "name": "New Arrival",
      "settings": [
        {
          "type": "product",
          "id": "product",
          "label": "Product"
        }
      ]
    }
  ]
}

这是我的 for 循环的简化版本:

{% if section.blocks.size > 0 %}
        {% for block in section.blocks %}
            <!-- Individual product values here -->
        {% endfor %}
    {% endif %}

通常,为了检索块内容,我会使用这样的东西:

{{ block.settings.product.title }} 

但是像这样使用产品类型时,必须有不同的方式来获取产品信息。

您可以使用: {%- assign product = all_products[block.settings.product] -%}

这将从块中获取您的产品。然后根据需要对 titleprice 等其他属性使用 product。例如:{{ product.title }}