2016-05-15 56 views

回答

4

看看下面的代碼。

<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> 

上面的代碼可以顯示集合頁面中產品的可用顏色。您可以採用相同的循環結構並顯示整個產品網格,而不僅僅顯示變體名稱。

+0

我在哪個文件中使用這個? – Ibrahim

+0

你能幫我顯示整個產品網格嗎? – Ibrahim

+1

我很樂意提供幫助。如果您正在使用網格佈局。你需要編輯Snippets/product-grid-item.liquid。這裏是要放置的代碼。 [鏈接](https://gist.githubusercontent.com/projoomexperts/793ee84852ff1528d8f051a08e954213/raw/fbbbe490303bf5c084eb3f1887cfb983eaf2f58a/product-grid-item.liquid) –

相關問題