SORT filter: sorting by vendor and type?

Highlighted
Tourist
20 0 2

Hi i use SORT to sort my collection by vendor, faster than sorting manually:
 

        <ul class="product-grid clearfix">		
		{% for product in collection.products %}
			{% assign sorted_products = products | sort:'vendor' %}
		{% endfor %}
				{% for product in sorted_products %}
	          		<li{% cycle '', '', ' class="last-in-row"' %}>
            			{% include 'product-grid-item' %}
          			</li>
        		{% endfor %}
        </ul>
    


Found i could also sort by type. That's all pretty good, but it would be amazing if i could sort my collection by type first, and then by vendor within each type.
Tried this but doesn't work. Any ideas?

{% assign sorted_products = products | sort:'type','vendor' %}

Thanks, 

Fred

0 Likes
Shopify Staff
Shopify Staff
5704 0 278

Hi Fred,

What you are asking for is not possible, no.

This said, you really ought to replace this:

{% for product in collection.products %}
  {% assign sorted_products = products | sort:'vendor' %}
{% endfor %}

With:

 {% assign sorted_products = products | sort:'vendor' %}

You are unnecessarily resorting several times on the same page, you only need to sort once.

That's kind of heavy on Shopify's servers!

And then you can iterate...

{% for product in sorted_products %}

Thanks! :D

Caroline from http://11heavens.com ∴ mllegeorgesand AT gmail DOT com
0 Likes
Tourist
20 0 2

Thanks Caroline, changed.
Thanks!

0 Likes
Shopify Staff
Shopify Staff
5704 0 278

Thank you, Fred!

Caroline from http://11heavens.com ∴ mllegeorgesand AT gmail DOT com
0 Likes
New Member
29 0 0

Where do I have to add these lines of code? Can anyone help me please?

0 Likes