Answers.Body: <p>This doesn't work out of the box with Craft as the category field is a relation field.</p>
  
  <p>However you should be able to use <a href="https://github.com/TopShelfCraft/SuperSort" rel="nofollow noreferrer">SuperSort</a> plugin.</p>
  
  <pre><code>{% set products = craft.commerce.products.type('coins').limit(null) %}
  {% set orderedProducts = products | supersort('sortAs', '{stateCat.first.stateImportance}' %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-15T09:35:01.363Z
Answers.LastActivityDate: 2017-06-15T09:35:01.363Z
Answers.UserDisplayName: pauliusef
Body: <p>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.</p>
  
  <p>This is what I've tried:</p>
  
  <pre><code>{% set products = craft.commerce.products.order('stateCat.stateImportance asc').type('coins').limit(null) %}
  </code></pre>
  
  <p>This doesn't seem to work, how can I accomplish this?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-15T22:40:38.973Z
Comments.Text: "This is because some states are more important than others". For example, any state is greater than Florida.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-15T22:40:51.880Z
Comments.Text: (Really hope you're not from Florida)
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-16T07:35:33.323Z
Comments.Text: 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
Comments.UserDisplayName: Branko
Tags: <ordering><queries><order><products>
Title: Sort products by category field value
ThreadText: # Sort products by category field value
  
  (Asked by: username_0 on 2017-06-15)
  
  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?
  
  **Tags:** ordering, queries, order, products
  
  > **Comments:**
  > **username_1**: "This is because some states are more important than others". For example, any state is greater than Florida.  
  > **username_1**: (Really hope you're not from Florida)  
  > **username_0**: 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  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2017-06-15. Score: 2 | Accepted answer
  
  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](https://github.com/TopShelfCraft/SuperSort) plugin.
  
  ```
  {% set products = craft.commerce.products.type('coins').limit(null) %}
  {% set orderedProducts = products | supersort('sortAs', '{stateCat.first.stateImportance}' %}
  
  ```
  
  
  ---
  
  