Unhold.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 Unhold 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::unhold';
  15. /**
  16. * Unhold 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(__('Can\'t unhold order.'));
  25. return $resultRedirect->setPath('sales/*/');
  26. }
  27. $order = $this->_initOrder();
  28. if ($order) {
  29. try {
  30. if (!$order->canUnhold()) {
  31. throw new \Magento\Framework\Exception\LocalizedException(__('Can\'t unhold order.'));
  32. }
  33. $this->orderManagement->unHold($order->getEntityId());
  34. $this->messageManager->addSuccessMessage(__('You released the order from holding status.'));
  35. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  36. $this->messageManager->addErrorMessage($e->getMessage());
  37. } catch (\Exception $e) {
  38. $this->messageManager->addErrorMessage(__('The order was not on hold.'));
  39. }
  40. $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]);
  41. return $resultRedirect;
  42. }
  43. $resultRedirect->setPath('sales/*/');
  44. return $resultRedirect;
  45. }
  46. }