Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PrintShipment.php
Go to the documentation of this file.
1 <?php
8 
11 
13 {
18 
22  protected $_coreRegistry;
23 
27  protected $resultPageFactory;
28 
35  public function __construct(
36  Context $context,
38  \Magento\Framework\Registry $registry,
40  ) {
41  $this->orderAuthorization = $orderAuthorization;
42  $this->_coreRegistry = $registry;
43  $this->resultPageFactory = $resultPageFactory;
44  parent::__construct($context);
45  }
46 
52  public function execute()
53  {
54  $shipmentId = (int)$this->getRequest()->getParam('shipment_id');
55  if ($shipmentId) {
56  $shipment = $this->_objectManager->create(\Magento\Sales\Model\Order\Shipment::class)->load($shipmentId);
57  $order = $shipment->getOrder();
58  } else {
59  $orderId = (int)$this->getRequest()->getParam('order_id');
60  $order = $this->_objectManager->create(\Magento\Sales\Model\Order::class)->load($orderId);
61  }
62  if ($this->orderAuthorization->canView($order)) {
63  $this->_coreRegistry->register('current_order', $order);
64  if (isset($shipment)) {
65  $this->_coreRegistry->register('current_shipment', $shipment);
66  }
68  $resultPage = $this->resultPageFactory->create();
69  $resultPage->addHandle('print');
70  return $resultPage;
71  } else {
73  $resultRedirect = $this->resultRedirectFactory->create();
74  if ($this->_objectManager->get(\Magento\Customer\Model\Session::class)->isLoggedIn()) {
75  $resultRedirect->setPath('*/*/history');
76  } else {
77  $resultRedirect->setPath('sales/guest/form');
78  }
79  return $resultRedirect;
80  }
81  }
82 }
$order
Definition: order.php:55
foreach($order->getItems() as $orderItem) $shipment
__construct(Context $context, OrderViewAuthorizationInterface $orderAuthorization, \Magento\Framework\Registry $registry, PageFactory $resultPageFactory)