OfficialAndy Posted July 17, 2021 Share Posted July 17, 2021 Hey, Is there any way to find OrderID from invoice? I have tried using the API and DB but that only works for the first Invoice that is generated for the order? I need to get the OrderID from new invoices that are generated. 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted July 22, 2021 Share Posted July 22, 2021 Internal classes have this: $Invoice = Invoice::find($InvoiceNumber); if ($Invoice and isset($Invoice->order->id) and $Invoice->order->id) $OrderID = $Invoice->order->id; 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 23, 2021 Share Posted July 23, 2021 On 22/07/2021 at 01:14, steven99 said: Internal classes have this: wouldn't that still only apply to the first invoice? a renewal invoice wouldn't (normally) contain an order ID. 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted July 23, 2021 Share Posted July 23, 2021 Well, that might be the case but still using internal classes and expanding on that: <?php //@author: steven99 function getOrderByInvoiceId($invoiceID) { $Invoice = Invoice::find($invoiceID); if ($Invoice) { if (isset($Invoice->order->id) and $Invoice->order->id) return [$Invoice->order->id]; else { //Ugh, we need to find it. $OrderIDs = []; foreach($Invoice->items as $item) { //Is it an addon item? if ($item->addon) $OrderID = $item->addon->orderid; //Is it a service item? elseif ($item->service) $OrderID = $item->service->orderid; //is it a domain itme/ elseif ($item->domain) $OrderID = $item->domain->orderid; if (!in_array($OrderID, $OrderIDs)) { $OrderIDs[] = $OrderID; } } return $OrderIDs; } } else return [] } 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.