123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Sales\Controller\Adminhtml;
- use Magento\Backend\App\Action;
- use Magento\Sales\Api\OrderManagementInterface;
- use Magento\Sales\Api\OrderRepositoryInterface;
- use Magento\Framework\Exception\NoSuchEntityException;
- use Magento\Framework\Exception\InputException;
- use Psr\Log\LoggerInterface;
- /**
- * Adminhtml sales orders controller
- *
- * @author Magento Core Team <core@magentocommerce.com>
- * @SuppressWarnings(PHPMD.NumberOfChildren)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- abstract class Order extends \Magento\Backend\App\Action
- {
- /**
- * Authorization level of a basic admin session
- *
- * @see _isAllowed()
- */
- const ADMIN_RESOURCE = 'Magento_Sales::sales_order';
- /**
- * Array of actions which can be processed without secret key validation
- *
- * @var string[]
- */
- protected $_publicActions = ['view', 'index'];
- /**
- * Core registry
- *
- * @var \Magento\Framework\Registry
- */
- protected $_coreRegistry = null;
- /**
- * @var \Magento\Framework\App\Response\Http\FileFactory
- */
- protected $_fileFactory;
- /**
- * @var \Magento\Framework\Translate\InlineInterface
- */
- protected $_translateInline;
- /**
- * @var \Magento\Framework\View\Result\PageFactory
- */
- protected $resultPageFactory;
- /**
- * @var \Magento\Framework\Controller\Result\JsonFactory
- */
- protected $resultJsonFactory;
- /**
- * @var \Magento\Framework\View\Result\LayoutFactory
- */
- protected $resultLayoutFactory;
- /**
- * @var \Magento\Framework\Controller\Result\RawFactory
- */
- protected $resultRawFactory;
- /**
- * @var OrderManagementInterface
- */
- protected $orderManagement;
- /**
- * @var OrderRepositoryInterface
- */
- protected $orderRepository;
- /**
- * @var LoggerInterface
- */
- protected $logger;
- /**
- * @param Action\Context $context
- * @param \Magento\Framework\Registry $coreRegistry
- * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
- * @param \Magento\Framework\Translate\InlineInterface $translateInline
- * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
- * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
- * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory
- * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
- * @param OrderManagementInterface $orderManagement
- * @param OrderRepositoryInterface $orderRepository
- * @param LoggerInterface $logger
- *
- * @SuppressWarnings(PHPMD.ExcessiveParameterList)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- public function __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
- ) {
- $this->_coreRegistry = $coreRegistry;
- $this->_fileFactory = $fileFactory;
- $this->_translateInline = $translateInline;
- $this->resultPageFactory = $resultPageFactory;
- $this->resultJsonFactory = $resultJsonFactory;
- $this->resultLayoutFactory = $resultLayoutFactory;
- $this->resultRawFactory = $resultRawFactory;
- $this->orderManagement = $orderManagement;
- $this->orderRepository = $orderRepository;
- $this->logger = $logger;
- parent::__construct($context);
- }
- /**
- * Init layout, menu and breadcrumb
- *
- * @return \Magento\Backend\Model\View\Result\Page
- */
- protected function _initAction()
- {
- $resultPage = $this->resultPageFactory->create();
- $resultPage->setActiveMenu('Magento_Sales::sales_order');
- $resultPage->addBreadcrumb(__('Sales'), __('Sales'));
- $resultPage->addBreadcrumb(__('Orders'), __('Orders'));
- return $resultPage;
- }
- /**
- * Initialize order model instance
- *
- * @return \Magento\Sales\Api\Data\OrderInterface|false
- */
- protected function _initOrder()
- {
- $id = $this->getRequest()->getParam('order_id');
- try {
- $order = $this->orderRepository->get($id);
- } catch (NoSuchEntityException $e) {
- $this->messageManager->addErrorMessage(__('This order no longer exists.'));
- $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
- return false;
- } catch (InputException $e) {
- $this->messageManager->addErrorMessage(__('This order no longer exists.'));
- $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
- return false;
- }
- $this->_coreRegistry->register('sales_order', $order);
- $this->_coreRegistry->register('current_order', $order);
- return $order;
- }
- /**
- * @return bool
- */
- protected function isValidPostRequest()
- {
- $formKeyIsValid = $this->_formKeyValidator->validate($this->getRequest());
- $isPost = $this->getRequest()->isPost();
- return ($formKeyIsValid && $isPost);
- }
- }
|