* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link http://www.temando.com/ */ abstract class AbstractBatchAction extends Action { const ADMIN_RESOURCE = 'Temando_Shipping::batches'; /** * @var BatchRepositoryInterface */ private $batchRepository; /** * @var BatchProviderInterface */ private $batchProvider; /** * AbstractBatchAction constructor. * @param Context $context * @param BatchRepositoryInterface $batchRepository * @param BatchProviderInterface $batchProvider */ public function __construct( Context $context, BatchRepositoryInterface $batchRepository, BatchProviderInterface $batchProvider ) { $this->batchRepository = $batchRepository; $this->batchProvider = $batchProvider; parent::__construct($context); } /** * @param RequestInterface $request * @return ResponseInterface|ResultInterface */ public function dispatch(RequestInterface $request) { $batchId = $request->getParam('batch_id'); try { $batch = $this->batchRepository->getById($batchId); // register batch for use in output rendering $this->batchProvider->setBatch($batch); } catch (NoSuchEntityException $e) { /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); return $resultForward->forward('noroute'); } return parent::dispatch($request); } }