Marketing | Creative | Strategy

Your faithful partner in the discovery of endless digital opportunity.

Take the First Step

SHOW ME THE MONEY: How To Find The Price Of The Most Expensive Item in a Shopify Store

Whether it’s for bragging rights, or you’re trying to give someone an idea of the prices of the products you sell, or you just want to know for the hell of it… sometimes it can be very useful to locate the price of the most expensive item in your Shopify store.
Seems like a simple question, however there could be some tricky pieces to this puzzles, because of the way that Shopify lists this information. So let’s start at the beginning… which if “Sound of Music” has taught us anything it’s that this... is a very good place to start.


THE IDEA

If you’ve worked with Shopify before and have a working knowledge of the code, the first thing that might come to your mind is to initialise the variable of the maximum price(maxPrice) to a very low value, or 0. Just to set that baseline. Then, you create a forloop, which runs through all of the products of the catalog to check if the price of the current product is higher than the maxPrice variable. If yes, then set the value of maxPrice to current product's price. Easy enough.


THE WORKAROUND

Unfortunately for everyone, a forloop in Shopify can only search through 50 products at a time, so if the online shop has more than 50 products, some values will remain not checked. Certainly an issue, considering you’re trying to find the most expensive item in the shop, not the most expensive item out of 50 items.


THE PROCESS

In order to avoid this limitation, we could use the collection “All”, a collection that contains all the products in the shop - if it was created. Now, if you haven’t created this collection this is where you create it. For this coding purpose we sort the collection. Don’t worry if you set the order of “All” collection manually in shopify administration, they will keep this order on the “All” collection page. The sorting we will make is just for coding purpose so this will not have any visual impact on the page.
Here’s the code that orders the products by price:

{% assign productsMax = collections['all'].products | sort: 'price' %}

Once you have the value for productsMax, you can check the name and the price of the product with the highest price using Javascript to display the result in the console using the following script:

<script>
console.log("Title: " + {{ productsMax[-1].title | json }} );
console.log("MaxPrice: " + {{ productsMax[-1].price_max | money | json }} );
</script>

Now that you have this collection set, you can also use the earlier forloop idea as well to determine the highest price now that you are no longer limited by the 50 items in this new “All” collection.

Knowledge is power, we all know that, and knowing the most expensive item in your Shopify store will arm you next time you need to speak to the client or a customer who’s ready to drop some major cash. Know your limits low and high.

Ionut-Radu Pastiu
Web Developer
Shopify is not just an online store, it is the future of commerce, and I have a doctorate in this field of study. I can slice and dice, mix and match, or come up with a completely new way to make your Shopify page exactly what you want it to be. I’m fluent in Javascript, jQuery, and Liquid when building the foundation, which I decorate with a combination of CSS and SCSS. You can dream it, I can build, they will shop... trust me.
close[x]

Get A Quote

Please fill out the quote form to the best of your knowledge. Once submitted, a Slicedbread representative will be back in touch with you as soon as possible.

* Required Fields