Track.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 RMA Shipment Track Action
  15. *
  16. * @package Temando\Shipping\Controller
  17. * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
  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 Track 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. * @param Context $context
  34. * @param RmaAccess $rmaAccess
  35. * @param ShipmentRepositoryInterface $shipmentRepository
  36. */
  37. public function __construct(
  38. Context $context,
  39. RmaAccess $rmaAccess,
  40. ShipmentRepositoryInterface $shipmentRepository
  41. ) {
  42. $this->rmaAccess = $rmaAccess;
  43. $this->shipmentRepository = $shipmentRepository;
  44. parent::__construct($context);
  45. }
  46. /**
  47. * @return ResultInterface
  48. */
  49. public function execute()
  50. {
  51. // load and register current RMA shipment
  52. $extShipmentId = $this->getRequest()->getParam('shipment_id');
  53. try {
  54. $extShipment = $this->shipmentRepository->getById($extShipmentId);
  55. $this->rmaAccess->setCurrentRmaShipment($extShipment);
  56. } catch (LocalizedException $exception) {
  57. $message = "Shipment '$extShipmentId' not found.";
  58. $this->messageManager->addExceptionMessage($exception, __($message));
  59. /** @var \Magento\Framework\Controller\Result\Forward $resultForward */
  60. $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
  61. $resultForward->forward('noroute');
  62. return $resultForward;
  63. }
  64. /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
  65. $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
  66. $resultPage->getConfig()->getTitle()->prepend(__('Tracking Information'));
  67. return $resultPage;
  68. }
  69. }