Is there a way to get all orders from the database which have items with attribute set "X"? I know there is sales_flat_order_item and this might be a good point to start, but somehow I am stuck here.
Thanks for helping!
orders
Is there a way to get all orders from the database which have items with attribute set "X"? I know there is sales_flat_order_item and this might be a good point to start, but somehow I am stuck here.
Thanks for helping!
Best Answer
Option 1. Multiple queries - Not the best one
Now in
$productIds
you have all the products ids from attribute set 4. If this is an empty array then it's clear you will not have any orders for this attribute set and you don't need to go on.If it's not empty....
now get the order objects.
I'm sure there is a way to optimize the queries that run, but this should work.
Option 2. With a query - if you need a fast look in the db
And here is a query, just for the fun of it.
Option 3. One select - clean.
Based on the query above I realized you can get the list of orders with a single select built the magento way.
Then just do
foreach
loop on the$collection
and you will have the orders.