Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PrintInvoice.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  $invoiceId = (int)$this->getRequest()->getParam('invoice_id');
53  if ($invoiceId) {
54  $invoice = $this->_objectManager->create(
55  \Magento\Sales\Api\InvoiceRepositoryInterface::class
56  )->get($invoiceId);
57  $order = $invoice->getOrder();
58  } else {
59  $order = $this->_coreRegistry->registry('current_order');
60  }
61 
62  if ($this->orderAuthorization->canView($order)) {
63  if (isset($invoice)) {
64  $this->_coreRegistry->register('current_invoice', $invoice);
65  }
66  return $this->resultPageFactory->create()->addHandle('print');
67  } else {
68  return $this->resultRedirectFactory->create()->setPath('sales/guest/form');
69  }
70  }
71 }
$order
Definition: order.php:55
$invoice
__construct(Context $context, OrderViewAuthorization $orderAuthorization, \Magento\Framework\Registry $registry, PageFactory $resultPageFactory, OrderLoader $orderLoader)