5

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.

4
  • 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? Commented May 31, 2016 at 10:22
  • Orders which contain one or more Products of the merchant Commented May 31, 2016 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. Commented May 31, 2016 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. Commented Jun 1, 2016 at 9:26

2 Answers 2

4

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

1
  • Great stuff, I'll be able to make use of this right away. Commented Jun 9, 2016 at 12:40
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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