How do I show the lowest price in a collection?

Sean_Masterson
Shopify Partner
8 0 4

On my homepage I want to show the minimum price of a product in my shoes collection.

Right now my code is displaying the price of all my products in my shoes collection instead of just the lowest product price in the collection. 

Here is my code so far.

{% for product in collections.shoes.products %}
    {{ product.price_min | money }}
{% endfor %}

Thanks in advance!

Replies 6 (6)
Sean_Masterson
Shopify Partner
8 0 4

Well I figured it out on my own after 8 hours. I have no idea if this is best practice so if anybody has a better way to do it feel free to comment below.

In case anybody else is wondering how to do this what I did was make an array called shoesMin and then sorted it by price. Then I called the first item in the array.

{% assign shoesMin = collections.shoes.products | sort: 'price' %}
{{ shoesMin[0].price_min | money }}

 

If you want to get the max price in a collection you need to call the last item in the array like this.

{% assign shoesMax = collections.shoes.products | sort: 'price' %}
{{ shoesMax[-1].price_max | money }}

 

tim
Shopify Expert
2925 143 1041

Hi Sean,

the way you finally did it is actually a better way, because looping over all items in a collection is not possible if there are more then 50 products in a collection.

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
Sean_Masterson
Shopify Partner
8 0 4

Yeah I thought that was going to happen if I did happen to figure out a solution my origional way. Glad I looked into how arrays in Liquid work!

maike
New Member
2 0 0

Running Shoe Fit Tips Foot size: Shoe lasts (which determine shoe sizes) vary by manufacturer and even from one www.bootsshoppingonline.com shoes shoe model to another. http://www.bootsshoppingonline.com.sale. You may need a half-size or even a full size smaller or larger than you think. If you're unsure, have http://www.bootsshoppingonline.com shoes your feet measured. http://www.bootsshoppingonline.com. Try on shoes at the end of the day. Your feet normally swell a bit during the day's activities and http://www.bootsshoppingonline.com will be at their largest then. This helps you avoid buying that are too small. http://www.bootsshoppingonline.com. Aim for a thumbnail's length of extra space in the toebox. The width should be snug but allow a bit of room for your foot to move without rubbing. Laces should be snug but not tight. Barefoot shoes are an exception: Heel and toes should “fit like a glove”without any extra http://www.bootsshoppingonline.com space in the toes.

 

ntrweb
New Member
1 0 0

Dude this is awesome. Thank you so much for this code. 

Atiqur_Rahman
Shopify Partner
17 1 15

It's possible up to 1000 products available in a collection. See the code example below:

      {% assign c_handle = collection.handle %}
      {% paginate collections[c_handle].products by 999  %}
      	{% assign shoesMin = collections[c_handle].products | sort: 'price' %}

        <div class="testMe">
          <h1>Minimum Price: {{ shoesMin[0].price | money }}</h1>

          <h1>Maximum Price: {{ shoesMin[-1].handle | money }}</h1>
        </div>
      
      {% endpaginate %}
If you have any requirement, please email me directly to ratiqur807@gmail.com

I'm the GENUINE EXPERT that you might need today!