View.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. use Magento\Backend\App\Action\Context;
  9. use Magento\Framework\App\ObjectManager;
  10. use Magento\Framework\Registry;
  11. use Magento\Sales\Api\InvoiceRepositoryInterface;
  12. use Magento\Sales\Model\Order\InvoiceRepository;
  13. abstract class View 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 Registry
  23. */
  24. protected $registry;
  25. /**
  26. * @var \Magento\Backend\Model\View\Result\ForwardFactory
  27. */
  28. protected $resultForwardFactory;
  29. /**
  30. * @var InvoiceRepositoryInterface
  31. */
  32. protected $invoiceRepository;
  33. /**
  34. * @param Context $context
  35. * @param Registry $registry
  36. * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
  37. */
  38. public function __construct(
  39. Context $context,
  40. Registry $registry,
  41. \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
  42. ) {
  43. $this->registry = $registry;
  44. parent::__construct($context);
  45. $this->resultForwardFactory = $resultForwardFactory;
  46. }
  47. /**
  48. * Invoice information page
  49. *
  50. * @return \Magento\Backend\Model\View\Result\Forward
  51. */
  52. public function execute()
  53. {
  54. $resultForward = $this->resultForwardFactory->create();
  55. if ($this->getRequest()->getParam('invoice_id')) {
  56. $resultForward->setController('order_invoice')
  57. ->setParams(['come_from' => 'invoice'])
  58. ->forward('view');
  59. } else {
  60. $resultForward->forward('noroute');
  61. }
  62. return $resultForward;
  63. }
  64. /**
  65. * @return \Magento\Sales\Model\Order\Invoice|bool
  66. */
  67. protected function getInvoice()
  68. {
  69. try {
  70. $invoice = $this->getInvoiceRepository()
  71. ->get($this->getRequest()->getParam('invoice_id'));
  72. $this->registry->register('current_invoice', $invoice);
  73. } catch (\Exception $e) {
  74. $this->messageManager->addErrorMessage(__('Invoice capturing error'));
  75. return false;
  76. }
  77. return $invoice;
  78. }
  79. /**
  80. * @return InvoiceRepository
  81. *
  82. * @deprecated 100.1.0
  83. */
  84. private function getInvoiceRepository()
  85. {
  86. if ($this->invoiceRepository === null) {
  87. $this->invoiceRepository = ObjectManager::getInstance()
  88. ->get(InvoiceRepositoryInterface::class);
  89. }
  90. return $this->invoiceRepository;
  91. }
  92. }