/
PrintShipment.php
68 lines (63 loc) · 2.03 KB
/
PrintShipment.php
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
<?php
/**
*
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sales\Controller\Guest;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
class PrintShipment extends \Magento\Sales\Controller\AbstractController\PrintShipment
{
/**
* @var OrderLoader
*/
protected $orderLoader;
/**
* @param Context $context
* @param OrderViewAuthorization $orderAuthorization
* @param \Magento\Framework\Registry $registry
* @param PageFactory $resultPageFactory
* @param OrderLoader $orderLoader
*/
public function __construct(
Context $context,
OrderViewAuthorization $orderAuthorization,
\Magento\Framework\Registry $registry,
PageFactory $resultPageFactory,
OrderLoader $orderLoader
) {
$this->orderLoader = $orderLoader;
parent::__construct(
$context,
$orderAuthorization,
$registry,
$resultPageFactory
);
}
/**
* {@inheritdoc}
*/
public function execute()
{
$result = $this->orderLoader->load($this->_request);
if ($result instanceof \Magento\Framework\Controller\ResultInterface) {
return $result;
}
$shipmentId = (int)$this->getRequest()->getParam('shipment_id');
if ($shipmentId) {
$shipment = $this->_objectManager->create('Magento\Sales\Model\Order\Shipment')->load($shipmentId);
$order = $shipment->getOrder();
} else {
$order = $this->_coreRegistry->registry('current_order');
}
if ($this->orderAuthorization->canView($order)) {
if (isset($shipment)) {
$this->_coreRegistry->register('current_shipment', $shipment);
}
return $this->resultPageFactory->create()->addHandle('print');
} else {
return $this->resultRedirectFactory->create()->setPath('sales/guest/form');
}
}
}