1

All of my products have a category field called stateCat. These state categories have a field called stateImportance. This is because some states are more important than others and I want to sort the products based on that stateImportance number. I have no idea how to do this.

This is what I've tried:

{% set products = craft.commerce.products.order('stateCat.stateImportance asc').type('coins').limit(null) %}

This doesn't seem to work, how can I accomplish this?

  • 2
    "This is because some states are more important than others". For example, any state is greater than Florida. – Brad Bell Jun 15 '17 at 22:40
  • (Really hope you're not from Florida) – Brad Bell Jun 15 '17 at 22:40
  • Im not from the US and I'm making a website with coins that are 200-300 years old. Coins from certain states in The Netherlands have more value than others. These have to be on top – Branko Jun 16 '17 at 7:35
2

This doesn't work out of the box with Craft as the category field is a relation field.

However you should be able to use SuperSort plugin.

{% set products = craft.commerce.products.type('coins').limit(null) %}
{% set orderedProducts = products | supersort('sortAs', '{stateCat.first.stateImportance}' %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.