For those wondering, I rolled my own.
Started off by receiving a comma separated string of product ID's
Then executed this query to the 'snapshot' json column in commerce_lineitems like so:
$fetchLineQuery = 'SELECT * FROM commerce_lineitems WHERE snapshot->"$.productId" IN ('.$productIdList.')';
$fetchLineExec = Craft::$app->db->createCommand($fetchLineQuery)->queryAll();
Then for each result, ran a foreach loop. Inside the foreach
loop we call Order::find()
with isComplete()
, isPaid()
, and also id()
where the ID will be received from the foreach
loop from $orderIdQuery$fetchLineExec
. As a side, the order info is stored into a cache variable to make sure we don't run Order::find()
multiple times for the same order.
I then put all the data I need into an array.
To export it as a CSV was fairly simple using fputcsv
I can't share the code as it was a client project, but hopefully this should be enough to get you all going.