首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Shopify -是否可以按“Vendor”过滤

Shopify -是否可以按“Vendor”过滤
EN

Stack Overflow用户
提问于 2017-08-21 02:52:06
回答 2查看 3.8K关注 0票数 1

Shopify似乎只允许通过标签进行过滤。如果您想要按Vendor (这是一个标准的Shopify Field)进行过滤,您首先需要创建具有相同名称的标签,并在过滤器侧边栏中手动使用这些标签。

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

EN

回答 2

Stack Overflow用户

发布于 2020-06-12 08:05:13

经过近两天的试验和错误,再加上对论坛和文档的大量挖掘,我想出了这段代码来创建一个有效的供应商过滤器。

请注意以下事项:

  1. 类和ID由模块化购物主题创建。我刚刚重用了它们,请为您的主题使用适当的类/I。
  2. 供应商过滤器不能与标签过滤器或排序依据选项一起使用。这些都是隐藏的,如下所述。

代码语言:javascript
复制
          <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"是从供应商下拉列表中获取值并更新网址(URL)所必需的JavaScript。
  2. for product_vendor in shop.vendors是获取所有供应商并将它们逐一提供给URL所必需的一种液体。当使用供应商过滤器时,if collection.current_vendor contains product_vendor也是一种液体。它检查活动的供应商筛选器,并在页面提供了上面#1中的JavaScript使用的URL后在下拉列表中选择它。
  3. reloaded.
  4. The
  5. {{ product_vendor }}向列表提供实际的供应商名称。如果选择了供应商筛选器,
  6. and collection.current_vendor == blank将告诉页面隐藏标记并对下拉列表进行排序。

以下是Shopify Docs,它确实对我有帮助。本文假设您已经理解了for loopif statements,它们是编程的基本组件。

  1. Understanding shop.vendors
  2. Understanding collection.current_vendor
  3. Understanding url_for_vendor
  4. Understanding product_vendor
  5. Understanding blank
票数 1
EN

Stack Overflow用户

发布于 2017-08-21 05:03:04

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

在最近与Shopify的现场问答中提到了这一点,并确认他们正在测试这一点。更多信息可在此处查看:https://youtu.be/MDqDIIyxIcU?t=2078

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45785750

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档