Answers.Body: <p><a href="https://craftcommerce.com/docs/variant-model#saleprice" rel="nofollow noreferrer">https://craftcommerce.com/docs/variant-model#saleprice</a></p>
  
  <p>The comment on the documentation leads me to believe you can just use <code>salePrice</code> for your filtering as it will be equal to the <code>defaultPrice</code> if there is no sale.</p>
  
  <p>So:</p>
  
  <pre><code>{% set queryParams = {
          relatedTo: category,
          salePrice: [
              'and',
              '&gt;= ' ~ 0,
              '&lt;= ' ~ 90,
          ]
      }
  %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-06T13:52:11.860Z
Answers.Text: I tried this initially too, but that is part of the variant model so not accessible using `craft.commerce.products`
Answers.UserDisplayName: MalTek
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-06T13:54:54.123Z
Answers.Text: `defaultVariant` is, but does not seem to be accessible either.
  
  `{% set queryParams = {
              relatedTo: category,
              defaultVariant: {
                  salePrice: [
                      'and',
                      '>= ' ~ 0,
                      '<= ' ~ 90,
                  ]
              }
          }
      %}`
  
  Does not work either
Answers.UserDisplayName: MalTek
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-05T19:46:52.030Z
Answers.LastActivityDate: 2017-07-05T19:46:52.030Z
Answers.UserDisplayName: jrothafer
Body: <p><strong>Building on from this question <a href="https://craftcms.stackexchange.com/questions/20093/how-can-i-filter-craft-commerce-products-by-price">How can I filter Craft Commerce products by price</a></strong></p>
  
  <p>I have a price filter in the store</p>
  
  <p>Using this code works fine for the normal price</p>
  
  <pre><code>{% set queryParams = {
          relatedTo: category,
          defaultPrice: [
              'and',
              '&gt;= ' ~ 0,
              '&lt;= ' ~ 90,
          ]
      }
  %}
  </code></pre>
  
  <p>but defaultPrice does not consider sale prices.</p>
  
  <p>So if a product is normally $99 but it is reduced to $89, it won't be returned</p>
  
  <p>I would have expected defaultPrice to store the <em>current price being charged</em>. So the sale price if it was on sale.</p>
  
  <p><strong>Is it possible to filter by price and include sale prices?</strong></p>
  
  <p>I've spent hours now on something I thought would be simple. It seems the only way to get this information is to get the products and loop through them. Checking for sale prices.</p>
  
  <p>Do I have to create a plugin to make a usable price filter?</p>
  
Tags: <plugin-craftcommerce><filtering>
Title: How can I filter Craft Commerce products by the current price
ThreadText: # How can I filter Craft Commerce products by the current price
  
  (Asked by: username_0 on 2017-07-05)
  
  **Building on from this question [How can I filter Craft Commerce products by price](https://craftcms.stackexchange.com/questions/20093/how-can-i-filter-craft-commerce-products-by-price)**
  
  I have a price filter in the store
  
  Using this code works fine for the normal price
  
  ```
  {% set queryParams = {
          relatedTo: category,
          defaultPrice: [
              'and',
              '>= ' ~ 0,
              '<= ' ~ 90,
          ]
      }
  %}
  
  ```
  
  but defaultPrice does not consider sale prices.
  
  So if a product is normally $99 but it is reduced to $89, it won't be returned
  
  I would have expected defaultPrice to store the *current price being charged*. So the sale price if it was on sale.
  
  **Is it possible to filter by price and include sale prices?**
  
  I've spent hours now on something I thought would be simple. It seems the only way to get this information is to get the products and loop through them. Checking for sale prices.
  
  Do I have to create a plugin to make a usable price filter?
  
  **Tags:** plugin-craftcommerce, filtering
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-07-05. Score: 1
  
  <https://craftcommerce.com/docs/variant-model#saleprice>
  
  The comment on the documentation leads me to believe you can just use `salePrice` for your filtering as it will be equal to the `defaultPrice` if there is no sale.
  
  So:
  
  ```
  {% set queryParams = {
          relatedTo: category,
          salePrice: [
              'and',
              '>= ' ~ 0,
              '<= ' ~ 90,
          ]
      }
  %}
  
  ```
  
  > **Comments:**
  > **username_0**: I tried this initially too, but that is part of the variant model so not accessible using `craft.commerce.products`  
  > **username_0**: `defaultVariant` is, but does not seem to be accessible either.  `{% set queryParams = {             relatedTo: category,             defaultVariant: {                 salePrice: [                     'and',                     '>= ' ~ 0,                     '<= ' ~ 90,                 ]             }         }     %}`  Does not work either  
  
  ---
  
  