Jump to content
Sign in to follow this  
OfficialAndy

Get OrderID from InvoiceID?

Recommended Posts

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.

Share this post


Link to post
Share on other sites

Internal classes have this:

 $Invoice = Invoice::find($InvoiceNumber);
 if ($Invoice and isset($Invoice->order->id) and $Invoice->order->id)
        $OrderID = $Invoice->order->id;

 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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 []
 
}

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated