问题
I have a shopify store and I added a color swatch palette to my shopify collections page .
How do I display only the colors that are in stock?
http://gloria22x.myshopify.com/collections/alle-produkte?sort_by=manual
Thanks, Alex
{% 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 %}
<img class="colorpalette" src="{{ color | downcase | strip_newlines | strip_html | replace:'ß','ss' | remove: ' ' | append: '.png' | asset_url }}" title="{{ color | camelize }}" alt="{{ color | camelize }}" width="16" height="16"/>
{% capture tempList %}
{{colorlist | append: color | append: ‘ ‘}}
{% endcapture %}
{% assign colorlist = tempList %}
{% endunless %}
{% endfor %}
{% endif %}
{% endfor %}
回答1:
You need to check the inventory_quantity for each variant. Try this:
...
{% for variant in product.variants %}
{% if variant.inventory_quantity > 0 %}
...
{% endif %}
{% endfor %}
...
来源:https://stackoverflow.com/questions/26496823/color-swatch-on-collections-page-i-shopify