Hold.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Controller\Adminhtml\Order;
  7. class Hold extends \Magento\Sales\Controller\Adminhtml\Order
  8. {
  9. /**
  10. * Authorization level of a basic admin session
  11. *
  12. * @see _isAllowed()
  13. */
  14. const ADMIN_RESOURCE = 'Magento_Sales::hold';
  15. /**
  16. * Hold order
  17. *
  18. * @return \Magento\Backend\Model\View\Result\Redirect
  19. */
  20. public function execute()
  21. {
  22. $resultRedirect = $this->resultRedirectFactory->create();
  23. if (!$this->isValidPostRequest()) {
  24. $this->messageManager->addErrorMessage(__('You have not put the order on hold.'));
  25. return $resultRedirect->setPath('sales/*/');
  26. }
  27. $order = $this->_initOrder();
  28. if ($order) {
  29. try {
  30. $this->orderManagement->hold($order->getEntityId());
  31. $this->messageManager->addSuccessMessage(__('You put the order on hold.'));
  32. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  33. $this->messageManager->addErrorMessage($e->getMessage());
  34. } catch (\Exception $e) {
  35. $this->messageManager->addErrorMessage(__('You have not put the order on hold.'));
  36. }
  37. $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]);
  38. return $resultRedirect;
  39. }
  40. $resultRedirect->setPath('sales/*/');
  41. return $resultRedirect;
  42. }
  43. }