From 6167176fea454b29a961c1d5df6220696a1ca65e Mon Sep 17 00:00:00 2001 From: Kannakiraj123 Date: Sat, 28 Aug 2021 09:28:54 +0530 Subject: [PATCH 1/3] Fix print invoice issue --- .../AbstractController/PrintInvoice.php | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php b/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php index d06f0cc87360e..6a268c31c4c76 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php @@ -8,6 +8,7 @@ use Magento\Framework\App\Action\Context; use Magento\Framework\View\Result\PageFactory; +use Magento\Framework\Message\ManagerInterface; abstract class PrintInvoice extends \Magento\Framework\App\Action\Action { @@ -26,21 +27,29 @@ abstract class PrintInvoice extends \Magento\Framework\App\Action\Action */ protected $resultPageFactory; + /** + * @var PageFactory + */ + protected $messageManager; + /** * @param Context $context * @param OrderViewAuthorizationInterface $orderAuthorization * @param \Magento\Framework\Registry $registry * @param PageFactory $resultPageFactory + * @param ManagerInterface $messageManager */ public function __construct( Context $context, OrderViewAuthorizationInterface $orderAuthorization, \Magento\Framework\Registry $registry, - PageFactory $resultPageFactory + PageFactory $resultPageFactory, + ManagerInterface $messageManager ) { $this->orderAuthorization = $orderAuthorization; $this->_coreRegistry = $registry; $this->resultPageFactory = $resultPageFactory; + $this->messageManager = $messageManager; parent::__construct($context); } @@ -53,9 +62,21 @@ public function execute() { $invoiceId = (int)$this->getRequest()->getParam('invoice_id'); if ($invoiceId) { - $invoice = $this->_objectManager->create( - \Magento\Sales\Api\InvoiceRepositoryInterface::class - )->get($invoiceId); + try { + $invoice = $this->_objectManager->create( + \Magento\Sales\Api\InvoiceRepositoryInterface::class + )->get($invoiceId); + }catch (\Magento\Framework\Exception\NoSuchEntityException $e) { + $this->messageManager->addError(__($e->getMessage())); + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + if ($this->_objectManager->get(\Magento\Customer\Model\Session::class)->isLoggedIn()) { + $resultRedirect->setPath('*/*/history'); + } else { + $resultRedirect->setPath('sales/guest/form'); + } + return $resultRedirect; + } $order = $invoice->getOrder(); } else { $orderId = (int)$this->getRequest()->getParam('order_id'); From 15b7a15b1c6203757cc20a4e1c5745f98f8f05a2 Mon Sep 17 00:00:00 2001 From: Kannakiraj123 Date: Sat, 28 Aug 2021 10:01:35 +0530 Subject: [PATCH 2/3] Fix print shipment issue --- .../AbstractController/PrintShipment.php | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php index 6d79e6ef6b323..1450c5b2e51f6 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php @@ -7,6 +7,7 @@ namespace Magento\Sales\Controller\AbstractController; use Magento\Framework\App\Action\Context; +use Magento\Framework\Message\ManagerInterface; use Magento\Framework\View\Result\PageFactory; abstract class PrintShipment extends \Magento\Framework\App\Action\Action @@ -26,21 +27,29 @@ abstract class PrintShipment extends \Magento\Framework\App\Action\Action */ protected $resultPageFactory; + /** + * @var PageFactory + */ + protected $messageManager; + /** * @param Context $context * @param OrderViewAuthorizationInterface $orderAuthorization * @param \Magento\Framework\Registry $registry * @param PageFactory $resultPageFactory + * @param ManagerInterface $messageManager */ public function __construct( Context $context, OrderViewAuthorizationInterface $orderAuthorization, \Magento\Framework\Registry $registry, - PageFactory $resultPageFactory + PageFactory $resultPageFactory, + ManagerInterface $messageManager ) { $this->orderAuthorization = $orderAuthorization; $this->_coreRegistry = $registry; $this->resultPageFactory = $resultPageFactory; + $this->messageManager = $messageManager; parent::__construct($context); } @@ -53,7 +62,19 @@ public function execute() { $shipmentId = (int)$this->getRequest()->getParam('shipment_id'); if ($shipmentId) { - $shipment = $this->_objectManager->create(\Magento\Sales\Model\Order\Shipment::class)->load($shipmentId); + try { + $shipment = $this->_objectManager->create(\Magento\Sales\Model\Order\Shipment::class)->load($shipmentId); + }catch (\Magento\Framework\Exception\NoSuchEntityException $e) { + $this->messageManager->addError(__($e->getMessage())); + /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + if ($this->_objectManager->get(\Magento\Customer\Model\Session::class)->isLoggedIn()) { + $resultRedirect->setPath('*/*/history'); + } else { + $resultRedirect->setPath('sales/guest/form'); + } + return $resultRedirect; + } $order = $shipment->getOrder(); } else { $orderId = (int)$this->getRequest()->getParam('order_id'); From 97a4a9e2612223aa3b72a8d605d6990db15b2f05 Mon Sep 17 00:00:00 2001 From: Kannakiraj123 Date: Sat, 28 Aug 2021 11:17:25 +0530 Subject: [PATCH 3/3] fix compilation issue --- .../Controller/AbstractController/PrintInvoice.php | 11 +---------- .../Controller/AbstractController/PrintShipment.php | 12 +----------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php b/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php index 6a268c31c4c76..fbcc80e626337 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php @@ -8,7 +8,6 @@ use Magento\Framework\App\Action\Context; use Magento\Framework\View\Result\PageFactory; -use Magento\Framework\Message\ManagerInterface; abstract class PrintInvoice extends \Magento\Framework\App\Action\Action { @@ -27,29 +26,21 @@ abstract class PrintInvoice extends \Magento\Framework\App\Action\Action */ protected $resultPageFactory; - /** - * @var PageFactory - */ - protected $messageManager; - /** * @param Context $context * @param OrderViewAuthorizationInterface $orderAuthorization * @param \Magento\Framework\Registry $registry * @param PageFactory $resultPageFactory - * @param ManagerInterface $messageManager */ public function __construct( Context $context, OrderViewAuthorizationInterface $orderAuthorization, \Magento\Framework\Registry $registry, - PageFactory $resultPageFactory, - ManagerInterface $messageManager + PageFactory $resultPageFactory ) { $this->orderAuthorization = $orderAuthorization; $this->_coreRegistry = $registry; $this->resultPageFactory = $resultPageFactory; - $this->messageManager = $messageManager; parent::__construct($context); } diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php index 1450c5b2e51f6..ed9df9f802584 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php @@ -7,7 +7,6 @@ namespace Magento\Sales\Controller\AbstractController; use Magento\Framework\App\Action\Context; -use Magento\Framework\Message\ManagerInterface; use Magento\Framework\View\Result\PageFactory; abstract class PrintShipment extends \Magento\Framework\App\Action\Action @@ -27,29 +26,21 @@ abstract class PrintShipment extends \Magento\Framework\App\Action\Action */ protected $resultPageFactory; - /** - * @var PageFactory - */ - protected $messageManager; - /** * @param Context $context * @param OrderViewAuthorizationInterface $orderAuthorization * @param \Magento\Framework\Registry $registry * @param PageFactory $resultPageFactory - * @param ManagerInterface $messageManager */ public function __construct( Context $context, OrderViewAuthorizationInterface $orderAuthorization, \Magento\Framework\Registry $registry, - PageFactory $resultPageFactory, - ManagerInterface $messageManager + PageFactory $resultPageFactory ) { $this->orderAuthorization = $orderAuthorization; $this->_coreRegistry = $registry; $this->resultPageFactory = $resultPageFactory; - $this->messageManager = $messageManager; parent::__construct($context); } @@ -65,7 +56,6 @@ public function execute() try { $shipment = $this->_objectManager->create(\Magento\Sales\Model\Order\Shipment::class)->load($shipmentId); }catch (\Magento\Framework\Exception\NoSuchEntityException $e) { - $this->messageManager->addError(__($e->getMessage())); /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); if ($this->_objectManager->get(\Magento\Customer\Model\Session::class)->isLoggedIn()) {