Shopify - 是否可以按供应商'过滤

时间:2017-08-20 18:52:06

标签: shopify liquid

似乎Shopify只允许按标签过滤。如果您想按供应商(标准Shopify字段)进行过滤,首先需要创建具有相同名称的标签,并在过滤器侧栏中手动使用这些标签。

这是对的吗?似乎非常不必要,更重要的是使动态更新变得困难。

2 个答案:

答案 0 :(得分:0)

Shopify目前不允许供应商过滤(同时保持与供应商的收集关系)。

最近在Shopify的现场Q& A中提到了这一点,并且确认他们正在对此进行测试。更多信息可以在这里看到:https://youtu.be/MDqDIIyxIcU?t=2078

你现在必须坚持使用标签。

答案 1 :(得分:0)

经过将近2天的反复试验,再深入研究论坛和文档,我想到了这段代码来创建有效的Vendor过滤器。

请注意以下几点:

  1. 这些类和ID由Modular Shopify主题创建。我刚刚重用了它们,请为您的主题使用适当的类/ ID。
  2. 供应商过滤器不适用于标签过滤器或排序依据选项。这些被隐藏,如下所述。
          <div class="grid-filter block">

            {% comment %} New Vendor Filter {% endcomment %}
            <div class="tag-filter block">
                <label for="#vendorFilter">Browse by Vendor</label>
                <span class="selectArrow"></span>
                <select class="vendorFilter filter" id="vendorFilter" onChange="window.location.href=this.value">
                  <option value="/collections/all">All</option>
                  {% for product_vendor in shop.vendors %}
                    {% if collection.current_vendor contains product_vendor %}
                        <option value="{{ product_vendor | url_for_vendor }}" selected>{{ product_vendor }}</option>
                    {% else %}
                        <option value="{{ product_vendor | url_for_vendor }}">{{ product_vendor }}</option>
                    {% endif %}
                  {% endfor %}
                </select>
              </div>
            {% comment %} END New Vendor Filter {% endcomment %}

            {% if show_filter == true and collection.current_vendor == blank %}
              <div class="tag-filter block">
                <label for="#tagFilter">{{ 'collections.tag_filtering.filter_label' | t }}</label>
                <span class="selectArrow"></span>
                <select class="tagFilter filter" id="tagFilter">
                  <option value="/collections/{{ collection.handle }}">{{ 'collections.tag_filtering.default_filter' | t }}</option>
                  {% for tag in collection.all_tags %}
                    {% if current_tags contains tag %}
                      <option value="/collections/{{ collection.handle }}/{{ tag | handle }}" selected>{{ tag }}</option>
                    {% else %}
                      <option value="/collections/{{ collection.handle }}/{{ tag | handle }}">{{ tag }}</option>
                    {% endif %}
                  {% endfor %}
                </select>
              </div>
            {% endif %}
            {% if show_sort_filter == true and collection.current_vendor == blank %}
            <div class="collectionGrid-filter block">
              <label for="#collectionFilter">{{ 'collections.sorting_dropdown.label' | t }}</label>
              <span class="selectArrow"></span>
              {% assign sort_by = collection.sort_by %}
              <select class="filter" id="collectionFilter">
                <option value="">{{ 'collections.sorting_dropdown.all' | t }}</option>
                <option value="best-selling" {% if sort_by == "best-selling" %}selected{% endif %}>{{ 'collections.sorting_dropdown.best_selling' | t }}</option>
                <option value="price-ascending" {% if sort_by == "price-ascending" %}selected{% endif %}>{{ 'collections.sorting_dropdown.price_ascending' | t }}</option>
                <option value="price-descending" {% if sort_by == "price-descending" %}selected{% endif %}>{{ 'collections.sorting_dropdown.price_descending' | t }}</option>
                <option value="title-ascending" {% if sort_by == "title-ascending" %}selected{% endif %}>{{ 'collections.sorting_dropdown.title_ascending' | t }}</option>
                <option value="title-descending" {% if sort_by == "title-descending" %}selected{% endif %}>{{ 'collections.sorting_dropdown.title_descending' | t }}</option>
                <option value="created-ascending" {% if sort_by == "created-ascending" %}selected{% endif %}>{{ 'collections.sorting_dropdown.created_ascending' | t }}</option>
                <option value="created-descending" {% if sort_by == "created-descending" %}selected{% endif %}>{{ 'collections.sorting_dropdown.created_descending' | t }}</option>
              </select>
            </div>
            {% endif %}
          </div>

以下是值得一提的重要内容:

  1. onChange="window.location.href=this.value"是一段JavaScript,需要从供应商下拉列表中获取值并更新网址(URL)。
  2. for product_vendor in shop.vendors有点流动性,它可以吸引所有供应商并在下拉菜单中一次为其提供一个。
  3. 使用供应商过滤器时,if collection.current_vendor contains product_vendor也需要一些Liquid。重新加载页面后,它将检查活动的供应商过滤器并在下拉列表中选择它。
  4. {{ product_vendor | url_for_vendor }}提供了上面#1中的JavaScript使用的URL。
  5. {{ product_vendor }}将实际的供应商名称提供给列表。
  6. 如果选择了供应商过滤器,and collection.current_vendor == blank会告诉页面隐藏“标记和排序”下拉列表。

这确实对我有帮助。假设您已经了解for loopif statements,它们是编程的基本组成部分。

  1. 了解shop.vendors
  2. 了解collection.current_vendor
  3. 了解url_for_vendor
  4. 了解product_vendor
  5. 了解blank