【问题标题】:Shopify show color variants in collection but not size variantShopify 在集合中显示颜色变体,但不显示尺寸变体
【发布时间】:2017-03-16 02:49:24
【问题描述】:

目标是在 Shopify 的产品系列页面上仅显示其他颜色变体。 使用供应主题。我在集合中显示所有变体图像,但如果存在变体,我只想显示颜色变体。有些物品没有变体,有些物品有尺寸变体。有的有颜色,有的有大小和颜色。我不想在集合页面上显示颜色的所有尺寸变体。 收集.液体

  {% for product in collection.products %}
    {% for variant in product.variants %} 
    {% if has_sidebar %}
      {% assign grid_item_width = 'large--one-quarter medium--one-third small--one-half' %}
    {% else %}
      {% assign grid_item_width = 'large--one-fifth medium--one-third small--one-half' %}
    {% endif %}
    {% include 'product-grid-item' %}

  {% else %}

    <div class="grid-item">
      <p>{{ 'collections.general.no_matches' | t }}</p>
    </div>
   {% endfor %}
  {% endfor %}

</div>

product-grid-item.liquid

<div class="grid-item {{ grid_item_width }}{% if sold_out %} sold-out{% endif %}{% if on_sale %} on-sale{% endif %}">

{% 如果售罄 %} {{ 'products.product.sold_out' | }} {% 万一 %} 我想我需要从 if 语句开始检查变体,然后为颜色添加一个 forloop。 {% for option in product.options %} {% if option == 'Color' %}

任何帮助将不胜感激。

【问题讨论】:

    标签: shopify liquid


    【解决方案1】:

    这样的事情应该可以帮助您入门。

    首先我们循环产品选项,然后我们说我们只想要颜色或颜色,然后我们循环属于该选项的所有变体...获取颜色并创建一个带有标题的列表项。

    <ul>
    {% for option in product.options %}
      {% if option == "Color" or option == "Colour" %}
        {% assign index = forloop.index0 %}
        {% assign colorlist = '' %}
        {% assign color = '' %}
        {% for variant in product.variants %}
          {% capture color %}
            {{ variant.options[index] }}
          {% endcapture %}
          {% unless colorlist contains color %}
            <li><span class="color-{{color | handle }}"><a href="{{variant.id}}">{{color}}</a></span></li>
            {% capture tempList %}
              {{colorlist | append: color | append: ' '}}
            {% endcapture %}
            {% assign colorlist = tempList %}
          {% endunless %}
        {% endfor %}
      {% endif %}
    {% endfor %}
    </ul>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 2017-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多