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
Highlighted
Shopify Staff
Shopify Staff
5704 1 323

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

0 Likes
Highlighted
Tourist
20 0 2

Thanks Caroline, changed.
Thanks!

0 Likes
Highlighted
Shopify Staff
Shopify Staff
5704 1 323

Thank you, Fred!

0 Likes
Highlighted
Tourist
52 0 1

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

0 Likes
Highlighted
New Member
8 0 0

Capture.JPGwe need option availability on sort by menu

0 Likes
Highlighted
Tourist
6 0 0

Hi,

where exactly u added this code? meaning in which liquid file I want to use this code but not getting where to add exactly..
thank you.

0 Likes