Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
OrderLoader.php
Go to the documentation of this file.
1 <?php
8 
11 use Magento\Framework\Controller\Result\ForwardFactory;
13 
15 {
19  protected $orderFactory;
20 
24  protected $registry;
25 
30 
34  protected $url;
35 
40 
44  protected $redirectFactory;
45 
54  public function __construct(
55  \Magento\Sales\Model\OrderFactory $orderFactory,
58  \Magento\Framework\UrlInterface $url,
59  ForwardFactory $resultForwardFactory,
61  ) {
62  $this->orderFactory = $orderFactory;
63  $this->orderAuthorization = $orderAuthorization;
64  $this->registry = $registry;
65  $this->url = $url;
66  $this->resultForwardFactory = $resultForwardFactory;
67  $this->redirectFactory = $redirectFactory;
68  }
69 
74  public function load(RequestInterface $request)
75  {
76  $orderId = (int)$request->getParam('order_id');
77  if (!$orderId) {
79  $resultForward = $this->resultForwardFactory->create();
80  return $resultForward->forward('noroute');
81  }
82 
83  $order = $this->orderFactory->create()->load($orderId);
84 
85  if ($this->orderAuthorization->canView($order)) {
86  $this->registry->register('current_order', $order);
87  return true;
88  }
90  $resultRedirect = $this->redirectFactory->create();
91  return $resultRedirect->setUrl($this->url->getUrl('*/*/history'));
92  }
93 }
$order
Definition: order.php:55
__construct(\Magento\Sales\Model\OrderFactory $orderFactory, OrderViewAuthorizationInterface $orderAuthorization, Registry $registry, \Magento\Framework\UrlInterface $url, ForwardFactory $resultForwardFactory, RedirectFactory $redirectFactory)
Definition: OrderLoader.php:54