Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Order.php
Go to the documentation of this file.
1 <?php
7 
13 use Psr\Log\LoggerInterface;
14 
22 abstract class Order extends \Magento\Backend\App\Action
23 {
29  const ADMIN_RESOURCE = 'Magento_Sales::sales_order';
30 
36  protected $_publicActions = ['view', 'index'];
37 
43  protected $_coreRegistry = null;
44 
48  protected $_fileFactory;
49 
53  protected $_translateInline;
54 
58  protected $resultPageFactory;
59 
63  protected $resultJsonFactory;
64 
69 
73  protected $resultRawFactory;
74 
78  protected $orderManagement;
79 
83  protected $orderRepository;
84 
88  protected $logger;
89 
106  public function __construct(
107  Action\Context $context,
108  \Magento\Framework\Registry $coreRegistry,
109  \Magento\Framework\App\Response\Http\FileFactory $fileFactory,
110  \Magento\Framework\Translate\InlineInterface $translateInline,
111  \Magento\Framework\View\Result\PageFactory $resultPageFactory,
112  \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
113  \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory,
114  \Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
117  LoggerInterface $logger
118  ) {
119  $this->_coreRegistry = $coreRegistry;
120  $this->_fileFactory = $fileFactory;
121  $this->_translateInline = $translateInline;
122  $this->resultPageFactory = $resultPageFactory;
123  $this->resultJsonFactory = $resultJsonFactory;
124  $this->resultLayoutFactory = $resultLayoutFactory;
125  $this->resultRawFactory = $resultRawFactory;
126  $this->orderManagement = $orderManagement;
127  $this->orderRepository = $orderRepository;
128  $this->logger = $logger;
129  parent::__construct($context);
130  }
131 
137  protected function _initAction()
138  {
139  $resultPage = $this->resultPageFactory->create();
140  $resultPage->setActiveMenu('Magento_Sales::sales_order');
141  $resultPage->addBreadcrumb(__('Sales'), __('Sales'));
142  $resultPage->addBreadcrumb(__('Orders'), __('Orders'));
143  return $resultPage;
144  }
145 
151  protected function _initOrder()
152  {
153  $id = $this->getRequest()->getParam('order_id');
154  try {
155  $order = $this->orderRepository->get($id);
156  } catch (NoSuchEntityException $e) {
157  $this->messageManager->addErrorMessage(__('This order no longer exists.'));
158  $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
159  return false;
160  } catch (InputException $e) {
161  $this->messageManager->addErrorMessage(__('This order no longer exists.'));
162  $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
163  return false;
164  }
165  $this->_coreRegistry->register('sales_order', $order);
166  $this->_coreRegistry->register('current_order', $order);
167  return $order;
168  }
169 
173  protected function isValidPostRequest()
174  {
175  $formKeyIsValid = $this->_formKeyValidator->validate($this->getRequest());
176  $isPost = $this->getRequest()->isPost();
177  return ($formKeyIsValid && $isPost);
178  }
179 }
$id
Definition: fieldset.phtml:14
$order
Definition: order.php:55
__()
Definition: __.php:13
__construct(Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\App\Response\Http\FileFactory $fileFactory, \Magento\Framework\Translate\InlineInterface $translateInline, \Magento\Framework\View\Result\PageFactory $resultPageFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory, \Magento\Framework\Controller\Result\RawFactory $resultRawFactory, OrderManagementInterface $orderManagement, OrderRepositoryInterface $orderRepository, LoggerInterface $logger)
Definition: Order.php:106