From ea4cacaf420ec574319d7c45d06bba1408cfd477 Mon Sep 17 00:00:00 2001 From: magentoabu Date: Thu, 17 Apr 2025 19:17:12 +0530 Subject: [PATCH 1/4] fix invoice error --- .../AbstractController/PrintInvoice.php | 18 +++++++++++++++--- .../AbstractController/PrintShipment.php | 13 ++++++++++++- 2 files changed, 27 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..fbcc80e626337 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php @@ -53,9 +53,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'); diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php index 6d79e6ef6b323..295f5cd9c4688 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php @@ -53,7 +53,18 @@ 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) { + /** @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 840edfdf9e6cd02bf999742f415e928f0490f5ca Mon Sep 17 00:00:00 2001 From: magentoabu Date: Fri, 18 Apr 2025 15:39:17 +0530 Subject: [PATCH 2/4] static test fixed --- .../Controller/AbstractController/PrintInvoice.php | 6 +++--- .../Controller/AbstractController/PrintShipment.php | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php b/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php index fbcc80e626337..74eef9d9ada11 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php @@ -1,8 +1,8 @@ _objectManager->create( \Magento\Sales\Api\InvoiceRepositoryInterface::class )->get($invoiceId); - }catch (\Magento\Framework\Exception\NoSuchEntityException $e) { + } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { $this->messageManager->addError(__($e->getMessage())); /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php index 295f5cd9c4688..5844ff498eb25 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php @@ -1,8 +1,8 @@ getRequest()->getParam('shipment_id'); if ($shipmentId) { - try { - $shipment = $this->_objectManager->create(\Magento\Sales\Model\Order\Shipment::class)->load($shipmentId); - }catch (\Magento\Framework\Exception\NoSuchEntityException $e) { + try { + $shipment = $this->_objectManager + ->create(\Magento\Sales\Model\Order\Shipment::class) + ->load($shipmentId); + } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); if ($this->_objectManager->get(\Magento\Customer\Model\Session::class)->isLoggedIn()) { From 48f1bfd335c34959e3863bd580000a3fb632a639 Mon Sep 17 00:00:00 2001 From: magentoabu Date: Sat, 19 Apr 2025 20:43:05 +0530 Subject: [PATCH 3/4] warnings fixed static test --- .../Sales/Controller/AbstractController/PrintShipment.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php index 5844ff498eb25..539b7af1cdc5c 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php @@ -57,16 +57,16 @@ public function execute() $shipment = $this->_objectManager ->create(\Magento\Sales\Model\Order\Shipment::class) ->load($shipmentId); - } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { + } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { /** @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; - } + } + return $resultRedirect; + } $order = $shipment->getOrder(); } else { $orderId = (int)$this->getRequest()->getParam('order_id'); From 73fe84c6207cac165057a51c6c169cca6cf14678 Mon Sep 17 00:00:00 2001 From: magentoabu Date: Mon, 21 Apr 2025 19:37:04 +0530 Subject: [PATCH 4/4] issue fixed --- .../Sales/Controller/AbstractController/PrintShipment.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php index 539b7af1cdc5c..90bf9a4c5f231 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php +++ b/app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php @@ -64,9 +64,9 @@ public function execute() $resultRedirect->setPath('*/*/history'); } else { $resultRedirect->setPath('sales/guest/form'); - } + } return $resultRedirect; - } + } $order = $shipment->getOrder(); } else { $orderId = (int)$this->getRequest()->getParam('order_id');