PrintInvoice.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Sales\Controller\Guest;
  8. use Magento\Framework\App\Action\Context;
  9. use Magento\Framework\View\Result\PageFactory;
  10. class PrintInvoice extends \Magento\Sales\Controller\AbstractController\PrintInvoice
  11. {
  12. /**
  13. * @var OrderLoader
  14. */
  15. protected $orderLoader;
  16. /**
  17. * @param Context $context
  18. * @param OrderViewAuthorization $orderAuthorization
  19. * @param \Magento\Framework\Registry $registry
  20. * @param PageFactory $resultPageFactory
  21. * @param OrderLoader $orderLoader
  22. */
  23. public function __construct(
  24. Context $context,
  25. OrderViewAuthorization $orderAuthorization,
  26. \Magento\Framework\Registry $registry,
  27. PageFactory $resultPageFactory,
  28. OrderLoader $orderLoader
  29. ) {
  30. $this->orderLoader = $orderLoader;
  31. parent::__construct(
  32. $context,
  33. $orderAuthorization,
  34. $registry,
  35. $resultPageFactory
  36. );
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function execute()
  42. {
  43. $result = $this->orderLoader->load($this->_request);
  44. if ($result instanceof \Magento\Framework\Controller\ResultInterface) {
  45. return $result;
  46. }
  47. $invoiceId = (int)$this->getRequest()->getParam('invoice_id');
  48. if ($invoiceId) {
  49. $invoice = $this->_objectManager->create(
  50. \Magento\Sales\Api\InvoiceRepositoryInterface::class
  51. )->get($invoiceId);
  52. $order = $invoice->getOrder();
  53. } else {
  54. $order = $this->_coreRegistry->registry('current_order');
  55. }
  56. if ($this->orderAuthorization->canView($order)) {
  57. if (isset($invoice)) {
  58. $this->_coreRegistry->register('current_invoice', $invoice);
  59. }
  60. return $this->resultPageFactory->create()->addHandle('print');
  61. } else {
  62. return $this->resultRedirectFactory->create()->setPath('sales/guest/form');
  63. }
  64. }
  65. }