Re: Impulse theme, sort all products on sale last in the collection by default

Impulse theme, sort all products on sale last in the collection by default

GlennAppsal
Shopify Partner
8 1 4

I want all my collection pages to sort the products by default so that all products on sale are shown last in the collection. I have a metafield on my products with sale true/false to know which products are on sale or not. I tried to make a loop over the products in the collection page and sort the products on sale last. It was working, but pagination is the problem. It sorted all products for each page with the products on sale last, So each page was sorted separately, but I want all products on sale to show in the very end of the collection on the last pages. My loop obviously only sorted each page instead of the whole collection.  

Replies 3 (3)

ThePrimeWeb
Shopify Partner
2139 616 525

Hey @GlennAppsal,

Could you not assign the array to a variable first, sort it by the metafield and then loop over it? 


Example code:

 

 

{% assign products_by_metafield = collection.products | sort: "your_meta_field" %}

{% for product in products_by_metafield %}
  <h2>{{ product.title }}</h2>
{% endfor %}

 

 

 

Was I helpful?

Buy me a coffee

🙂

Need help with your store? contact@theprimeweb.com or check out the website
Check out our interview with Shopify!

dylancam90
Shopify Partner
6 0 1

Did you figure this out? I am having the same exact issue right now and do not have a meta field for on sale products so it’s a little more difficult. We also have pagination…

GlennAppsal
Shopify Partner
8 1 4

No, didnt find any solution that worked with the pagination