Body: <p>I have a great many products which have a date field (they're class dates) and I want to show the next three which have any stock left (available places). The following works fine to display the next three products:</p>
  
  <pre><code>{% set earliestDate = now %} 
  {% set latestDate = now | date_modify('+ 10 days') %}
  
  {% set products = craft.commerce.products({
    type: 'class',
    date: 'and, &gt; ' ~ earliestDate ~ ', &lt; ' ~ latestDate,
    order: 'date',
    limit: 3
  }) %}
  </code></pre>
  
  <p>But of course there's no reference to stock. If I add the hasStock parameter, like so:</p>
  
  <pre><code>{% set products = craft.commerce.products({
    hasVariant: {
      hasStock: true
    },
    type: 'class',
    date: 'and, &gt; ' ~ earliestDate ~ ', &lt; ' ~ latestDate,
    order: 'date',
    limit: 3
  }) %}
  </code></pre>
  
  <p>The results are different every time I load the page! Results vary but include:</p>
  
  <ul>
  <li>showing more than three products, e.g. 5 products</li>
  <li>no products being returned at all</li>
  <li>three products but products which are an earlier date being skipped</li>
  </ul>
  
  <p>Has anyone else encountered this? I can understand maybe different results than expected if hasStock items were being fetched before the rest of the query, but not why it would be different on every pageload. If it helps, no products are being returned outside the date range I'm supplying.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-11T05:06:45.803Z
Comments.Text: Is this still an issue?
Comments.UserDisplayName: Luke Holder
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-12T17:39:02.307Z
Comments.Text: Hi Luke. I got around this by avoiding querying using hasStock. It wasn't ideal but I haven't worked on that project for a while. Next time I do I'll have a look.
Comments.UserDisplayName: Clive Portman
Tags: <plugin-craftcommerce>
Title: Commerce products returning different results on page load
ThreadText: # Commerce products returning different results on page load
  
  (Asked by: username_0 on 2017-01-25)
  
  I have a great many products which have a date field (they're class dates) and I want to show the next three which have any stock left (available places). The following works fine to display the next three products:
  
  ```
  {% set earliestDate = now %} 
  {% set latestDate = now | date_modify('+ 10 days') %}
  
  {% set products = craft.commerce.products({
    type: 'class',
    date: 'and, > ' ~ earliestDate ~ ', < ' ~ latestDate,
    order: 'date',
    limit: 3
  }) %}
  
  ```
  
  But of course there's no reference to stock. If I add the hasStock parameter, like so:
  
  ```
  {% set products = craft.commerce.products({
    hasVariant: {
      hasStock: true
    },
    type: 'class',
    date: 'and, > ' ~ earliestDate ~ ', < ' ~ latestDate,
    order: 'date',
    limit: 3
  }) %}
  
  ```
  
  The results are different every time I load the page! Results vary but include:
  
  * showing more than three products, e.g. 5 products
  * no products being returned at all
  * three products but products which are an earlier date being skipped
  
  Has anyone else encountered this? I can understand maybe different results than expected if hasStock items were being fetched before the rest of the query, but not why it would be different on every pageload. If it helps, no products are being returned outside the date range I'm supplying.
  
  **Tags:** plugin-craftcommerce
  
  > **Comments:**
  > **username_1**: Is this still an issue?  
  > **username_0**: Hi username_1. I got around this by avoiding querying using hasStock. It wasn't ideal but I haven't worked on that project for a while. Next time I do I'll have a look.  
  
  ---
  
  ## 0 answers
  
  