AssignPost.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Sales\Controller\Adminhtml\Order\Status;
  8. use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
  9. class AssignPost extends \Magento\Sales\Controller\Adminhtml\Order\Status implements HttpPostActionInterface
  10. {
  11. /**
  12. * Save status assignment to state
  13. *
  14. * @return \Magento\Backend\Model\View\Result\Redirect
  15. */
  16. public function execute()
  17. {
  18. $data = $this->getRequest()->getPostValue();
  19. /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
  20. $resultRedirect = $this->resultRedirectFactory->create();
  21. if ($data) {
  22. $state = $this->getRequest()->getParam('state');
  23. $isDefault = $this->getRequest()->getParam('is_default');
  24. $visibleOnFront = $this->getRequest()->getParam('visible_on_front');
  25. $status = $this->_initStatus();
  26. if ($status && $status->getStatus()) {
  27. try {
  28. $status->assignState($state, $isDefault, $visibleOnFront);
  29. $this->messageManager->addSuccessMessage(__('You assigned the order status.'));
  30. return $resultRedirect->setPath('sales/*/');
  31. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  32. $this->messageManager->addErrorMessage($e->getMessage());
  33. } catch (\Exception $e) {
  34. $this->messageManager->addExceptionMessage(
  35. $e,
  36. __('Something went wrong while assigning the order status.')
  37. );
  38. }
  39. } else {
  40. $this->messageManager->addErrorMessage(__('We can\'t find this order status.'));
  41. }
  42. return $resultRedirect->setPath('sales/*/assign');
  43. }
  44. return $resultRedirect->setPath('sales/*/');
  45. }
  46. }