Color swatch on collections page I Shopify

陌路散爱 提交于 2021-02-20 04:31:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!