2016-05-15 8 views

Antwort

4

Schauen Sie sich die folgenden Codes an.

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

Der obige Code kann die verfügbaren Farben eines Produkts in der Sammlungsseite anzeigen. Sie können die gleiche Schleifenstruktur verwenden und das gesamte Produktraster anzeigen, anstatt nur den Variantennamen anzuzeigen.

+0

in welcher Datei verwende ich das? – Ibrahim

+0

Können Sie mir helfen, das gesamte Produktraster anzuzeigen? – Ibrahim

+1

Ich würde gerne helfen. Wenn Sie das Rasterlayout verwenden. Sie müssen die Snippets/product-grid-item.liquid bearbeiten. Hier ist der Code zu platzieren. [link] (https://gist.githubusercontent.com/projoomexperts/793ee84852ff1528d8f051a08e954213/raw/fbbbe490303bf5c084eb3f1887cfb983eaf2f58a/product-grid-item.liquid) –

Verwandte Themen