Shopify 在系列中显示颜色变体,但不显示尺寸变体

1 liquid shopify

目标是在 Shopify 的“系列”页面上仅显示其他颜色变体。使用供应主题。我正在显示集合中的所有变体图像,但只想显示颜色变体(如果存在变体)。有些商品没有款式,有些商品有尺寸款式。有的有颜色,有的有大小和颜色。我不想在产品系列页面上显示某种颜色的所有尺寸变体。采集.液体

  {% for product in collection.products %}
    {% for variant in product.variants %} 
    {% if has_sidebar %}
      {% assign grid_item_width = 'large--one-quarter medium--one-third small--one-half' %}
    {% else %}
      {% assign grid_item_width = 'large--one-fifth medium--one-third small--one-half' %}
    {% endif %}
    {% include 'product-grid-item' %}

  {% else %}

    <div class="grid-item">
      <p>{{ 'collections.general.no_matches' | t }}</p>
    </div>
   {% endfor %}
  {% endfor %}

</div>
Run Code Online (Sandbox Code Playgroud)

产品网格项目.液体

<div class="grid-item {{ grid_item_width }}{% if sold_out %} sold-out{% endif %}{% if on_sale %} on-sale{% endif %}">
Run Code Online (Sandbox Code Playgroud)

{% if sell_out %} {{ 'products.product.sold_out' | 'products.product.sold_out' | {% if sell_out %} t }} {% endif %} 我想我需要从 if 语句开始检查变体,然后添加 forloop 颜色。{% for option in Product.options %} {% if option == 'Color' %}

任何帮助,将不胜感激。

小智 5

像这样的事情应该可以帮助你开始。

首先,我们循环产品选项,然后我们说我们只需要颜色或颜色,然后我们循环属于该选项的所有变体...抓取颜色并创建一个带有标题的列表项。

<ul>
{% for option in product.options %}
  {% if option == "Color" or option == "Colour" %}
    {% assign index = forloop.index0 %}
    {% assign colorlist = '' %}
    {% assign color = '' %}
    {% for variant in product.variants %}
      {% capture color %}
        {{ variant.options[index] }}
      {% endcapture %}
      {% unless colorlist contains color %}
        <li><span class="color-{{color | handle }}"><a href="{{variant.id}}">{{color}}</a></span></li>
        {% capture tempList %}
          {{colorlist | append: color | append: ' '}}
        {% endcapture %}
        {% assign colorlist = tempList %}
      {% endunless %}
    {% endfor %}
  {% endif %}
{% endfor %}
</ul>
Run Code Online (Sandbox Code Playgroud)