Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PrintPackage.php
Go to the documentation of this file.
1 <?php
8 
12 
14 {
20  const ADMIN_RESOURCE = 'Magento_Sales::shipment';
21 
25  protected $shipmentLoader;
26 
30  protected $_fileFactory;
31 
37  public function __construct(
38  Action\Context $context,
39  \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader,
40  \Magento\Framework\App\Response\Http\FileFactory $fileFactory
41  ) {
42  $this->shipmentLoader = $shipmentLoader;
43  $this->_fileFactory = $fileFactory;
44  parent::__construct($context);
45  }
46 
52  public function execute()
53  {
54  $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
55  $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
56  $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment'));
57  $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
58  $shipment = $this->shipmentLoader->load();
59 
60  if ($shipment) {
62  $pdf = $this->_objectManager->create(\Magento\Shipping\Model\Order\Pdf\Packaging::class)->getPdf($shipment);
63  return $this->_fileFactory->create(
64  'packingslip' . $this->_objectManager->get(
65  \Magento\Framework\Stdlib\DateTime\DateTime::class
66  )->date(
67  'Y-m-d_H-i-s'
68  ) . '.pdf',
69  $pdf->render(),
71  'application/pdf'
72  );
73  } else {
74  $this->_forward('noroute');
75  }
76  }
77 }
__construct(Action\Context $context, \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader, \Magento\Framework\App\Response\Http\FileFactory $fileFactory)
_forward($action, $controller=null, $module=null, array $params=null)
foreach($order->getItems() as $orderItem) $shipment