Answers.Body: <p>I managed to resolve this using the <a href="https://github.com/TopShelfCraft/SuperSort" rel="nofollow noreferrer">supersort</a> plugin and using 'defaultPrice' instead of 'price'. Example below:</p>
  
  <pre><code>{% set products = craft.products.type('accommodation').all() %}
  {% set order = products|supersort('sortAs', '{{ object.defaultPrice }}') %}
  
  {% for product in order %}
  
      // Products
  
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-02T14:18:48.517Z
Answers.LastActivityDate: 2019-01-02T14:18:48.517Z
Answers.UserDisplayName: Amy
Body: <p>Currently using Craft Commerce 2. </p>
  
  <p>I was wondering if it's possible to order products by the lowest priced variant. I have tried something along the lines of this, but it doesn't do anything different with the ordering:</p>
  
  <pre><code>{% set products = craft.products.type('accommodation').all() %}
  
  {% for product in products %}
     {% if product.getVariants()|length %}
  
          {% set variants = craft.variants ({
              product: product,
              orderBy: 'price asc'
          }) %}
  
          {% for purchasable in variants %}
              // Products Here
          {% endfor %}
  
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>I have also tried something else along the lines of this:</p>
  
  <pre><code>{% set products = craft.commerce.products({
      relatedTo: 'accommodation', 
      order: 'defaultPrice asc',
  }) %}
  </code></pre>
  
Tags: <craft3><plugin-craftcommerce2><order><variants>
Title: Order products by lowest product variant
ThreadText: # Order products by lowest product variant
  
  (Asked by: username_0 on 2018-12-20)
  
  Currently using Craft Commerce 2.
  
  I was wondering if it's possible to order products by the lowest priced variant. I have tried something along the lines of this, but it doesn't do anything different with the ordering:
  
  ```
  {% set products = craft.products.type('accommodation').all() %}
  
  {% for product in products %}
     {% if product.getVariants()|length %}
  
          {% set variants = craft.variants ({
              product: product,
              orderBy: 'price asc'
          }) %}
  
          {% for purchasable in variants %}
              // Products Here
          {% endfor %}
  
      {% endif %}
  {% endfor %}
  
  ```
  
  I have also tried something else along the lines of this:
  
  ```
  {% set products = craft.commerce.products({
      relatedTo: 'accommodation', 
      order: 'defaultPrice asc',
  }) %}
  
  ```
  
  **Tags:** craft3, plugin-craftcommerce2, order, variants
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-01-02. Score: 2 | Accepted answer
  
  I managed to resolve this using the [supersort](https://github.com/TopShelfCraft/SuperSort) plugin and using 'defaultPrice' instead of 'price'. Example below:
  
  ```
  {% set products = craft.products.type('accommodation').all() %}
  {% set order = products|supersort('sortAs', '{{ object.defaultPrice }}') %}
  
  {% for product in order %}
  
      // Products
  
  {% endfor %}
  
  ```
  
  
  ---
  
  