Shopify似乎只允许通过标签进行过滤。如果您想要按Vendor (这是一个标准的Shopify Field)进行过滤,您首先需要创建具有相同名称的标签,并在过滤器侧边栏中手动使用这些标签。
这是正确的吗?这似乎是非常不必要的,更重要的是使动态更新变得困难。
发布于 2020-06-12 08:05:13
经过近两天的试验和错误,再加上对论坛和文档的大量挖掘,我想出了这段代码来创建一个有效的供应商过滤器。
请注意以下事项:
<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>以下是值得一提的是:
onChange="window.location.href=this.value"是从供应商下拉列表中获取值并更新网址(URL)所必需的JavaScript。for product_vendor in shop.vendors是获取所有供应商并将它们逐一提供给URL所必需的一种液体。当使用供应商过滤器时,if collection.current_vendor contains product_vendor也是一种液体。它检查活动的供应商筛选器,并在页面提供了上面#1中的JavaScript使用的URL后在下拉列表中选择它。{{ product_vendor }}向列表提供实际的供应商名称。如果选择了供应商筛选器,and collection.current_vendor == blank将告诉页面隐藏标记并对下拉列表进行排序。以下是Shopify Docs,它确实对我有帮助。本文假设您已经理解了for loop和if statements,它们是编程的基本组件。
发布于 2017-08-21 05:03:04
Shopify目前不允许按供应商进行过滤(同时保持与供应商的集合关系)。
在最近与Shopify的现场问答中提到了这一点,并确认他们正在测试这一点。更多信息可在此处查看:https://youtu.be/MDqDIIyxIcU?t=2078
现在你必须坚持使用标签。
https://stackoverflow.com/questions/45785750
复制相似问题