Dispatch.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Controller\Adminhtml\Rma\Shipment;
  6. use Magento\Backend\App\Action;
  7. use Magento\Backend\App\Action\Context;
  8. use Magento\Framework\Controller\ResultFactory;
  9. use Magento\Framework\Controller\ResultInterface;
  10. use Magento\Framework\Exception\LocalizedException;
  11. use Temando\Shipping\Model\ResourceModel\Repository\ShipmentRepositoryInterface;
  12. use Temando\Shipping\Model\ResourceModel\Rma\RmaAccess;
  13. /**
  14. * Temando Dispatch Returns Shipment Action
  15. *
  16. * @package Temando\Shipping\Controller
  17. * @author Rhodri Davies <rhodri.davies@temando.com>
  18. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  19. * @link http://www.temando.com/
  20. */
  21. class Dispatch extends Action
  22. {
  23. const ADMIN_RESOURCE = 'Magento_Rma::magento_rma';
  24. /**
  25. * @var RmaAccess
  26. */
  27. private $rmaAccess;
  28. /**
  29. * @var ShipmentRepositoryInterface
  30. */
  31. private $shipmentRepository;
  32. /**
  33. * Dispatch constructor.
  34. * @param Context $context
  35. * @param RmaAccess $rmaAccess
  36. * @param ShipmentRepositoryInterface $shipmentRepository
  37. */
  38. public function __construct(
  39. Context $context,
  40. RmaAccess $rmaAccess,
  41. ShipmentRepositoryInterface $shipmentRepository
  42. ) {
  43. $this->rmaAccess = $rmaAccess;
  44. $this->shipmentRepository = $shipmentRepository;
  45. parent::__construct($context);
  46. }
  47. /**
  48. * @return ResultInterface
  49. */
  50. public function execute()
  51. {
  52. $rmaId = $this->getRequest()->getParam('rma_id');
  53. // load and register current RMA
  54. $rma = $this->rmaAccess->getById($rmaId);
  55. $this->rmaAccess->setCurrentRma($rma);
  56. // load and register current RMA shipment
  57. $extShipmentId = $this->getRequest()->getParam('ext_shipment_id');
  58. try {
  59. $extShipment = $this->shipmentRepository->getById($extShipmentId);
  60. $this->rmaAccess->setCurrentRmaShipment($extShipment);
  61. } catch (LocalizedException $exception) {
  62. $message = __("Shipment '%1' not found.", $extShipmentId);
  63. $this->messageManager->addExceptionMessage($exception, $message);
  64. /** @var \Magento\Framework\Controller\Result\Forward $resultForward */
  65. $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
  66. $resultForward->forward('noroute');
  67. return $resultForward;
  68. }
  69. /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
  70. $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
  71. $resultPage->getConfig()->getTitle()->prepend(__('Dispatch Return Shipment'));
  72. return $resultPage;
  73. }
  74. }