4

嘿,我在我的 shopify 网站上使用 brooklyn 主题。我有不同的产品会有颜色变体。当我点击收藏页面时,我想将该产品的所有颜色变体显示为单独的产品。我从昨晚开始就在谷歌上搜索,请帮忙。

4

1 回答 1

4

Look at the codes below.

<ul class="colorlist"> 
 {% for option in product.options %}
 {% if option == 'Color' %}
 {% assign index = forloop.index0 %}
 {% assign colorlist = '' %}
 {% assign color = '' %}
 {% for variant in product.variants %}
 {% capture color %}
 {{ variant.options[index] }}
 {% endcapture %}

 {% unless colorlist contains color %}
  {% if variant.available %}

  <li id="{{ variant.id }}" title="{{ variant.inventory_quantity }} In Stock" class="instock"><a href="{{ product.url | within: collection }}?variant={{ variant.id }}" style="background:{{ color | downcase }}">{{ color | downcase }}</a></li>

  {% else %}

  <li id="{{ variant.id }}" title="Out of Stock"  class="outstock" >{{ color | downcase }}</li>

  {% endif %}

{% capture tempList %}
{{colorlist | append: color | append: " " }}
{% endcapture %}
{% assign colorlist = tempList %}
{% endunless %}
{% endfor %}
{% endif %}
{% endfor %}
</ul>

The code above can display the available colors of a product in collection page. You can take the same loop structure and display the entire product grid instead of just displaying the variant name.

于 2016-05-15T13:47:37.013 回答