Email.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice;
  8. /**
  9. * Class Email
  10. *
  11. * @package Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice
  12. */
  13. abstract class Email extends \Magento\Backend\App\Action
  14. {
  15. /**
  16. * Authorization level of a basic admin session
  17. *
  18. * @see _isAllowed()
  19. */
  20. const ADMIN_RESOURCE = 'Magento_Sales::sales_invoice';
  21. /**
  22. * @var \Magento\Backend\Model\View\Result\ForwardFactory
  23. */
  24. protected $resultForwardFactory;
  25. /**
  26. * @param \Magento\Backend\App\Action\Context $context
  27. * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
  28. */
  29. public function __construct(
  30. \Magento\Backend\App\Action\Context $context,
  31. \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
  32. ) {
  33. parent::__construct($context);
  34. $this->resultForwardFactory = $resultForwardFactory;
  35. }
  36. /**
  37. * Notify user
  38. *
  39. * @return \Magento\Backend\Model\View\Result\Forward|\Magento\Backend\Model\View\Result\Redirect
  40. */
  41. public function execute()
  42. {
  43. $invoiceId = $this->getRequest()->getParam('invoice_id');
  44. if (!$invoiceId) {
  45. return $this->resultForwardFactory->create()->forward('noroute');
  46. }
  47. $invoice = $this->_objectManager->create(\Magento\Sales\Api\InvoiceRepositoryInterface::class)->get($invoiceId);
  48. if (!$invoice) {
  49. return $this->resultForwardFactory->create()->forward('noroute');
  50. }
  51. $this->_objectManager->create(
  52. \Magento\Sales\Api\InvoiceManagementInterface::class
  53. )->notify($invoice->getEntityId());
  54. $this->messageManager->addSuccessMessage(__('You sent the message.'));
  55. return $this->resultRedirectFactory->create()->setPath(
  56. 'sales/invoice/view',
  57. ['order_id' => $invoice->getOrder()->getId(), 'invoice_id' => $invoiceId]
  58. );
  59. }
  60. }