How to get order details by invoice id? I need order details by invoice id.
I got this how to get order deatils by invoice id? but this is for magento 1
How to get order details by invoice id? I need order details by invoice id.
I got this how to get order deatils by invoice id? but this is for magento 1
In magento2 this can be achieves as :
protected $objectManager;
public function __construct(
.....
\Magento\Framework\ObjectManagerInterface $objectManager,
.......
) {
...
$this->objectManager = $objectManager;
........
}
public function getOrder($invoice_id){
$invoice= $this->objectManager->create('Magento\Sales\Model\Order\Invoice')->load($invoice_id);
return $invoice->getOrder();
}
Use factory method instead of object manager
protected $invoiceFactory;
public function __construct(
...
\Magento\Sales\Model\Order\InvoiceFactory $invoiceFactory
...
) {
...
$this->invoiceFactory = $invoiceFactory;
...
}
public function getOrderByInvoice($invoiceId)
{
$invoice = $this->invoiceFactory->create()->load($invoiceId);
return $invoice->getOrder();
}