skip to Main Content

it seems Shopify only allows for filtering by tags. If you want to filter by Vendor (which is a standard Shopify Field) you first need to create tags with the same name and manually use those tags in the filter sidebar.

Is this correct? Seems very unnecessary and more importantly makes dynamic updates difficult.

2

Answers


  1. Shopify doesn’t allow for filtration by vendor at the moment (while keeping the collection relation to the vendor).

    This was mentioned in a recent live Q&A with Shopify and it was confirmed that they are testing this. More info can be seen here: https://youtu.be/MDqDIIyxIcU?t=2078

    You have to stick with the tags for now.

    Login or Signup to reply.
  2. After almost 2 days of trial and error, plus lots of digging into forums and the documentation, I came up with this bit of code to create a working Vendor filter.

    Please note the following:

    1. The classes and IDs were created by the Modular Shopify theme. I just reused them, please use the appropriate classes/IDs for your theme.
    2. The Vendor filter does not work with the tag filter or with the sort by option. Those were hidden as explained below.
              <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>
    

    Here are the important things worth mentioning:

    1. The onChange="window.location.href=this.value" is a bit of JavaScript necessary to grab the value from the vendor dropdown and to update the web address (URL).
    2. The for product_vendor in shop.vendors is a bit of Liquid necessary to grab all vendors and provide them one at a time to the dropdown.
    3. The if collection.current_vendor contains product_vendor is also a bit of Liquid necessary when the vendor filter is in use. It checks for an active vendor filter and selects it in the dropdown after the page has reloaded.
    4. The {{ product_vendor | url_for_vendor }} provides the URL used by the JavaScript in #1 above.
    5. The {{ product_vendor }} provides the actual vendor name to the list.
    6. The and collection.current_vendor == blank tells the page to hide the Tag and Sort dropdowns if a vendor filter was selected.

    Here are the Shopify Docs which really helped me. This assumes you already understand the for loop and if statements which are a basic component of programming.

    1. Understanding shop.vendors
    2. Understanding collection.current_vendor
    3. Understanding url_for_vendor
    4. Understanding product_vendor
    5. Understanding blank
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search