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 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.

  • 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? May 31 '16 at 10:22
  • Orders which contain one or more Products of the merchant May 31 '16 at 10:26
  • I'm getting no joy with this either. Almost as if the products on an order aren't set up like normal related elements. May 31 '16 at 15:10
  • 1
    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. Jun 1 '16 at 9:26

This is now possible as of Craft Commerce 1.1.1211 using the new hasPurchasables criteria attribute:


  • Great stuff, I'll be able to make use of this right away. Jun 9 '16 at 12:40

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!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.