1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
*/
namespace Temando\Shipping\Controller\Adminhtml\Batch;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Temando\Shipping\Model\BatchProviderInterface;
use Temando\Shipping\Model\ResourceModel\Repository\BatchRepositoryInterface;
/**
* Temando Batch Action
*
* Register a batch as referenced via request parameter
*
* @package Temando\Shipping\Controller
* @author Rhodri Davies <rhodri.davies@temando.com>
* @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);
}
}