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?

3
  • 2
    "This is because some states are more important than others". For example, any state is greater than Florida.
    – Brad Bell
    Commented Jun 15, 2017 at 22:40
  • (Really hope you're not from Florida)
    – Brad Bell
    Commented Jun 15, 2017 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
    Commented Jun 16, 2017 at 7:35

1 Answer 1

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}' %}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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