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 {
17  protected $orderLoader;
18 
26  public function __construct(
27  Context $context,
29  \Magento\Framework\Registry $registry,
32  ) {
33  $this->orderLoader = $orderLoader;
34  parent::__construct(
35  $context,
37  $registry,
39  );
40  }
41 
45  public function execute()
46  {
47  $result = $this->orderLoader->load($this->_request);
48  if ($result instanceof \Magento\Framework\Controller\ResultInterface) {
49  return $result;
50  }
51 
52  $shipmentId = (int)$this->getRequest()->getParam('shipment_id');
53  if ($shipmentId) {
54  $shipment = $this->_objectManager->create(\Magento\Sales\Model\Order\Shipment::class)->load($shipmentId);
55  $order = $shipment->getOrder();
56  } else {
57  $order = $this->_coreRegistry->registry('current_order');
58  }
59  if ($this->orderAuthorization->canView($order)) {
60  if (isset($shipment)) {
61  $this->_coreRegistry->register('current_shipment', $shipment);
62  }
63  return $this->resultPageFactory->create()->addHandle('print');
64  } else {
65  return $this->resultRedirectFactory->create()->setPath('sales/guest/form');
66  }
67  }
68 }
$order
Definition: order.php:55
__construct(Context $context, OrderViewAuthorization $orderAuthorization, \Magento\Framework\Registry $registry, PageFactory $resultPageFactory, OrderLoader $orderLoader)
foreach($order->getItems() as $orderItem) $shipment