Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi, I'm using this code on collection page, it works fine but not like what I need :
<div class="filter_co">
{% for vendor in shop.vendors %}
<a href="{{ vendor | url_for_vendor }}">{{ vendor }}</a>
{% endfor %}
</div>
In fact, I would like to display all the products vendor in the collection where I'm in, not all the products of the vendor in the entire shop...
And I would like to add a "display all" in case you select a vendor to duisplay again all the products from the collection...
Hope this clear... Any help please?
Hi @FredAz,
Not sure about the filtering features you want to use, but the code you need can be written as so:
<div class="filter_co">
{% for product_vendor in collection.all_vendors %}
{{ product_vendor | link_to_vendor }}
{% endfor %}
</div>
OK, so I kind of misread your request there (in my defense, it was rather late). Let's dive into it then:
In order to figure out the unique vendors that exist in a single collection, but not throughout the whole store, you'd need to loop through your collection's products and loop through each one's vendor. If we create an array where we can append each unique instance, then we can loop through that array and create a URL with a query string for each one. Kind of like this:
<div class="filter_co">
{% assign vendors = '' %}
{% for product in collection.products %}
{% unless vendors contains product.vendor %}
{% assign vendors = vendors | append: product.vendor | append: ', ' %}
{% endunless %}
{% endfor %}
{% assign vendors = vendors | split: ', ' | sort %}
<ul>
{% for vendor in vendors %}
<li><a href="/collections/{{ collection.handle }}/?vendor={{ vendor | escape }}" title="{{ vendor }} in {{ collection.title }}">{{ vendor }}</a></li>
{% endfor %}
<li><a href="/collections/{{ collection.handle }}" title="{{ collection.title }}">Display all</a></li>
</ul>
</div>
Now, for the Display All option, I imagine that you can just add a link to the collection URL (that last li above).
I have a vague feeling that there's an easier/more efficient way to do this (since you'd are effectively looping a collection's products twice), but my brain isn't working at full capacity at the moment tbh. If I come up with a better option, I'll let you know.
The above should produce a URL with a query string which filters products for a specific vendor in that specific collection. Each URL should look something like this:
https://yourstorename.com/collections/yourselectedcollection/?vendor=VendorName
If not, then there's something wrong with the output.
The collection page does not show the products of my suppliers, it always shows me the same ones, it does not filter by products (Filter)
My code
<div class="form-horizontal">
<select name="brands" class="btn--tertiary" onChange="window.location.href=this.value">
<option value="{{ collection.url }}">Marca</option>
{% for product_vendor in collection.all_vendors %}
<option {% if option.vendor == product_vendor %} selected {% endif %} value="{{ collection.url }}/?vendor={{ product_vendor | handle }}">{{ product_vendor }}</option>
{% endfor %}
</select>
</div>
My URL
misitioweb/collections/acabados/?vendor=generica
I do not understand what the problem is, he keeps showing me the same products
Find Global Growth Opportunities For Your Business with Shopify AcademyLearn how to exp...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025Expand into selling wholesale with Shopify Academy’s learning path, B2B on Shopify: Lau...
By Shopify Jan 28, 2025