Shopify - Order Products By Custom Field -


we have simple shopify store using free "meta fields editor" add simple custom field integer value each of products. products have meta value of 3, others 2 or 1. many have no meta value @ all. able display products in search results, meta field value entered each product in descending order (weighted ordering). however, despite ability set meta values , display them in search results , collections pages, shopify not make easy order or sort products custom meta field. in search results page able call custom meta value using {{item.metafields.important.important}} far have tried order products using method

{% assign products = collection.products | sort:  'item.metafields.important.important' %} {% product in products %}    {{ product.title }} {% endfor %} 

but results in null results. insight can give me in how display products in order of custom field appreciated!

after attempting find liquid solution able solve problem using custom metafields , jquery. in shopify collection template, added data attribute included each product so:

<div id="product_list"> <div data-imp="{{product.metafields.important.important}}" class="product_block" /> product #1 </div> <div data-imp="{{product.metafields.important.important}}" class="product_block" /> product #2 </div> </div> 

then used simple jquery function sort nodes data attribute in descending order

var $wrapper = $('#product_list');          $wrapper.find('.product_block').sort(function (a, b) {             return +b.dataset.imp - +a.dataset.imp;         })         .appendto( $wrapper );     } 

hope helps somebody!


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -