Order.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Controller\Adminhtml;
  7. use Magento\Backend\App\Action;
  8. use Magento\Sales\Api\OrderManagementInterface;
  9. use Magento\Sales\Api\OrderRepositoryInterface;
  10. use Magento\Framework\Exception\NoSuchEntityException;
  11. use Magento\Framework\Exception\InputException;
  12. use Psr\Log\LoggerInterface;
  13. /**
  14. * Adminhtml sales orders controller
  15. *
  16. * @author Magento Core Team <core@magentocommerce.com>
  17. * @SuppressWarnings(PHPMD.NumberOfChildren)
  18. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  19. */
  20. abstract class Order extends \Magento\Backend\App\Action
  21. {
  22. /**
  23. * Authorization level of a basic admin session
  24. *
  25. * @see _isAllowed()
  26. */
  27. const ADMIN_RESOURCE = 'Magento_Sales::sales_order';
  28. /**
  29. * Array of actions which can be processed without secret key validation
  30. *
  31. * @var string[]
  32. */
  33. protected $_publicActions = ['view', 'index'];
  34. /**
  35. * Core registry
  36. *
  37. * @var \Magento\Framework\Registry
  38. */
  39. protected $_coreRegistry = null;
  40. /**
  41. * @var \Magento\Framework\App\Response\Http\FileFactory
  42. */
  43. protected $_fileFactory;
  44. /**
  45. * @var \Magento\Framework\Translate\InlineInterface
  46. */
  47. protected $_translateInline;
  48. /**
  49. * @var \Magento\Framework\View\Result\PageFactory
  50. */
  51. protected $resultPageFactory;
  52. /**
  53. * @var \Magento\Framework\Controller\Result\JsonFactory
  54. */
  55. protected $resultJsonFactory;
  56. /**
  57. * @var \Magento\Framework\View\Result\LayoutFactory
  58. */
  59. protected $resultLayoutFactory;
  60. /**
  61. * @var \Magento\Framework\Controller\Result\RawFactory
  62. */
  63. protected $resultRawFactory;
  64. /**
  65. * @var OrderManagementInterface
  66. */
  67. protected $orderManagement;
  68. /**
  69. * @var OrderRepositoryInterface
  70. */
  71. protected $orderRepository;
  72. /**
  73. * @var LoggerInterface
  74. */
  75. protected $logger;
  76. /**
  77. * @param Action\Context $context
  78. * @param \Magento\Framework\Registry $coreRegistry
  79. * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
  80. * @param \Magento\Framework\Translate\InlineInterface $translateInline
  81. * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
  82. * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
  83. * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory
  84. * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
  85. * @param OrderManagementInterface $orderManagement
  86. * @param OrderRepositoryInterface $orderRepository
  87. * @param LoggerInterface $logger
  88. *
  89. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  90. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  91. */
  92. public function __construct(
  93. Action\Context $context,
  94. \Magento\Framework\Registry $coreRegistry,
  95. \Magento\Framework\App\Response\Http\FileFactory $fileFactory,
  96. \Magento\Framework\Translate\InlineInterface $translateInline,
  97. \Magento\Framework\View\Result\PageFactory $resultPageFactory,
  98. \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
  99. \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory,
  100. \Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
  101. OrderManagementInterface $orderManagement,
  102. OrderRepositoryInterface $orderRepository,
  103. LoggerInterface $logger
  104. ) {
  105. $this->_coreRegistry = $coreRegistry;
  106. $this->_fileFactory = $fileFactory;
  107. $this->_translateInline = $translateInline;
  108. $this->resultPageFactory = $resultPageFactory;
  109. $this->resultJsonFactory = $resultJsonFactory;
  110. $this->resultLayoutFactory = $resultLayoutFactory;
  111. $this->resultRawFactory = $resultRawFactory;
  112. $this->orderManagement = $orderManagement;
  113. $this->orderRepository = $orderRepository;
  114. $this->logger = $logger;
  115. parent::__construct($context);
  116. }
  117. /**
  118. * Init layout, menu and breadcrumb
  119. *
  120. * @return \Magento\Backend\Model\View\Result\Page
  121. */
  122. protected function _initAction()
  123. {
  124. $resultPage = $this->resultPageFactory->create();
  125. $resultPage->setActiveMenu('Magento_Sales::sales_order');
  126. $resultPage->addBreadcrumb(__('Sales'), __('Sales'));
  127. $resultPage->addBreadcrumb(__('Orders'), __('Orders'));
  128. return $resultPage;
  129. }
  130. /**
  131. * Initialize order model instance
  132. *
  133. * @return \Magento\Sales\Api\Data\OrderInterface|false
  134. */
  135. protected function _initOrder()
  136. {
  137. $id = $this->getRequest()->getParam('order_id');
  138. try {
  139. $order = $this->orderRepository->get($id);
  140. } catch (NoSuchEntityException $e) {
  141. $this->messageManager->addErrorMessage(__('This order no longer exists.'));
  142. $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
  143. return false;
  144. } catch (InputException $e) {
  145. $this->messageManager->addErrorMessage(__('This order no longer exists.'));
  146. $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
  147. return false;
  148. }
  149. $this->_coreRegistry->register('sales_order', $order);
  150. $this->_coreRegistry->register('current_order', $order);
  151. return $order;
  152. }
  153. /**
  154. * @return bool
  155. */
  156. protected function isValidPostRequest()
  157. {
  158. $formKeyIsValid = $this->_formKeyValidator->validate($this->getRequest());
  159. $isPost = $this->getRequest()->isPost();
  160. return ($formKeyIsValid && $isPost);
  161. }
  162. }