I have a similar requirement, I need to get invoice information after invoice save from admin.
I fulfil the requirement using the event observer.
app/code/Anshu/Customization/etc/adminhtml/events.xml
app/code/Anshu/Customization/etc/adminhtml/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="controller_action_postdispatch_sales_order_invoice_save">
<observer name="observer_admin_invoice_save" instance="Anshu\Customization\Observer\AnshuInvoiceSave" />
</event>
</config>
app/code/Anshu/Customization/Observer/AdminInvoiceSave.php
app/code/Anshu/Customization/Observer/AdminInvoiceSave.php
<?php
namespace Anshu\Customization\Observer;
use Magento\Framework\Event\ObserverInterface;
class AnshuInvoiceSave implements ObserverInterface
{
/**
* @var \Magento\Framework\Registry
*/
protected $_registry;
public function __construct(
\Magento\Framework\Registry $registry
)
{
$this->_registry = $registry;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$invoice = $this->getInvoiceObject();
// My Customization
}
private function getInvoiceObject()
{
return $this->_registry->registry('current_invoice');
}
}
Check if it is helpful to you.
Magento version was 2.2.1