resultForwardFactory = $resultForwardFactory; } /** * Notify user * * @return \Magento\Backend\Model\View\Result\Forward|\Magento\Backend\Model\View\Result\Redirect */ public function execute() { $invoiceId = $this->getRequest()->getParam('invoice_id'); if (!$invoiceId) { return $this->resultForwardFactory->create()->forward('noroute'); } $invoice = $this->_objectManager->create(\Magento\Sales\Api\InvoiceRepositoryInterface::class)->get($invoiceId); if (!$invoice) { return $this->resultForwardFactory->create()->forward('noroute'); } $this->_objectManager->create( \Magento\Sales\Api\InvoiceManagementInterface::class )->notify($invoice->getEntityId()); $this->messageManager->addSuccessMessage(__('You sent the message.')); return $this->resultRedirectFactory->create()->setPath( 'sales/invoice/view', ['order_id' => $invoice->getOrder()->getId(), 'invoice_id' => $invoiceId] ); } }