Answers.Body: <p>Looks like what I'm trying to do isn't possible (yet).  </p>
  
  <p>There is a suggestion for a solution (not created by me) already on the Craft Feedback site. So if you think this would be a useful thing to be able to do, get over there and vote it up, I know I have!</p>
  
  <p><a href="http://feedback.craftcms.com/forums/295386-commerce/suggestions/11458980-fetch-orders-based-on-a-product-and-or-product-var" rel="nofollow">http://feedback.craftcms.com/forums/295386-commerce/suggestions/11458980-fetch-orders-based-on-a-product-and-or-product-var</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-01T09:24:44.590Z
Answers.LastActivityDate: 2016-06-01T09:24:44.590Z
Answers.UserDisplayName: Steve Holland
Answers.Body: <p>This is now possible as of Craft Commerce 1.1.1211 using the new <code>hasPurchasables</code> criteria attribute:</p>
  
  <p><a href="https://craftcommerce.com/docs/craft-commerce-orders#haspurchasables">https://craftcommerce.com/docs/craft-commerce-orders#haspurchasables</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-09T12:40:09.457Z
Answers.Text: Great stuff, I'll be able to make use of this right away.
Answers.UserDisplayName: Steve Holland
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-09T12:35:18.770Z
Answers.LastActivityDate: 2016-06-09T12:35:18.770Z
Answers.UserDisplayName: Luke Holder
Body: <p>Each Product has a <code>Merchant</code> field which is standard Craft <code>User</code>. What I'd like to do is list out all Orders which contain one or more Products relating to the <code>currentUser</code>. I was hoping I'd be able to use <a href="https://craftcms.com/docs/relations">Relations</a> to accomplish this, so something like this:</p>
  
  <pre><code>{% set products = craft.commerce.products({
    'relatedTo': currentUser
  }) %}
  
  {% set orders = craft.commerce.orders.relatedTo({
    'sourceElement': products,
    'field': 'lineItems.purchasable.product'
  }).find %}
  </code></pre>
  
  <p>The first query works fine and returns only the <code>Products</code> relating to the <code>currentUser</code>, but when I try to use it as the basis for the second query, that's where it collapses in a big heap! Am I in the right ballpark, or isn't this possible in the way I'm trying?</p>
  
  <p>Any help gratefully received. </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-31T10:22:58.647Z
Comments.Text: Are you trying to list all Orders where *every* Product is from the merchant or Orders which contain *one or more* Products of the merchant?
Comments.UserDisplayName: Luke Pearce
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-31T10:26:13.603Z
Comments.Text: Orders which contain one or more Products of the merchant
Comments.UserDisplayName: Steve Holland
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-31T15:10:00.833Z
Comments.Text: I'm getting no joy with this either. Almost as if the products on an order aren't set up like normal related elements.
Comments.UserDisplayName: Luke Pearce
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-06-01T09:26:58.307Z
Comments.Text: Luke - I asked about this on Slack and there isn't a way to do what I'm asking, but some else has already suggested it on the Craft Feedback site. If you look at my new answer, there is a link where you can go and vote it up if you'd find it useful.
Comments.UserDisplayName: Steve Holland
Tags: <relations><plugin-craftcommerce>
Title: List only Orders containing specific Products
ThreadText: # List only Orders containing specific Products
  
  (Asked by: username_0 on 2016-05-31)
  
  Each Product has a `Merchant` field which is standard Craft `User`. What I'd like to do is list out all Orders which contain one or more Products relating to the `currentUser`. I was hoping I'd be able to use [Relations](https://craftcms.com/docs/relations) to accomplish this, so something like this:
  
  ```
  {% set products = craft.commerce.products({
    'relatedTo': currentUser
  }) %}
  
  {% set orders = craft.commerce.orders.relatedTo({
    'sourceElement': products,
    'field': 'lineItems.purchasable.product'
  }).find %}
  
  ```
  
  The first query works fine and returns only the `Products` relating to the `currentUser`, but when I try to use it as the basis for the second query, that's where it collapses in a big heap! Am I in the right ballpark, or isn't this possible in the way I'm trying?
  
  Any help gratefully received.
  
  **Tags:** relations, plugin-craftcommerce
  
  > **Comments:**
  > **username_1**: Are you trying to list all Orders where *every* Product is from the merchant or Orders which contain *one or more* Products of the merchant?  
  > **username_0**: Orders which contain one or more Products of the merchant  
  > **username_1**: I'm getting no joy with this either. Almost as if the products on an order aren't set up like normal related elements.  
  > **username_0**: username_1 - I asked about this on Slack and there isn't a way to do what I'm asking, but some else has already suggested it on the Craft Feedback site. If you look at my new answer, there is a link where you can go and vote it up if you'd find it useful.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-06-09. Score: 4 | Accepted answer
  
  This is now possible as of Craft Commerce 1.1.1211 using the new `hasPurchasables` criteria attribute:
  
  <https://craftcommerce.com/docs/craft-commerce-orders#haspurchasables>
  
  > **Comments:**
  > **username_0**: Great stuff, I'll be able to make use of this right away.  
  
  ---
  
  ### Answer by username_0 on 2016-06-01. Score: 3
  
  Looks like what I'm trying to do isn't possible (yet).
  
  There is a suggestion for a solution (not created by me) already on the Craft Feedback site. So if you think this would be a useful thing to be able to do, get over there and vote it up, I know I have!
  
  <http://feedback.craftcms.com/forums/295386-commerce/suggestions/11458980-fetch-orders-based-on-a-product-and-or-product-var>
  
  
  ---
  
  