Skip to content

Commit ff1a003

Browse files
author
govindasharma974
committed
Fixed issue related with wrong invoice id ,creditmemo id and shipmen id in url of view page.
1 parent 68770fc commit ff1a003

File tree

12 files changed

+254
-34
lines changed

12 files changed

+254
-34
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/View.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
namespace Magento\Sales\Controller\Adminhtml\Order\Creditmemo;
77

88
use Magento\Backend\App\Action;
9+
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
910

10-
class View extends \Magento\Backend\App\Action
11+
class View extends \Magento\Backend\App\Action implements HttpGetActionInterface
1112
{
1213
/**
1314
* Authorization level of a basic admin session
@@ -75,9 +76,9 @@ public function execute()
7576
}
7677
return $resultPage;
7778
} else {
78-
$resultForward = $this->resultForwardFactory->create();
79-
$resultForward->forward('noroute');
80-
return $resultForward;
79+
$resultRedirect = $this->resultRedirectFactory->create();
80+
$resultRedirect->setPath('sales/creditmemo');
81+
return $resultRedirect;
8182
}
8283
}
8384
}

app/code/Magento/Sales/Controller/Adminhtml/Order/CreditmemoLoader.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ public function load()
181181
$creditmemoId = $this->getCreditmemoId();
182182
$orderId = $this->getOrderId();
183183
if ($creditmemoId) {
184-
$creditmemo = $this->creditmemoRepository->get($creditmemoId);
184+
try {
185+
$creditmemo = $this->creditmemoRepository->get($creditmemoId);
186+
} catch (\Exception $e) {
187+
$this->messageManager->addErrorMessage(__('This creditmemo no longer exists.'));
188+
return false;
185189
} elseif ($orderId) {
186190
$data = $this->getCreditmemo();
187191
$order = $this->orderFactory->create()->load($orderId);

app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/View.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ public function execute()
4444
{
4545
$invoice = $this->getInvoice();
4646
if (!$invoice) {
47-
/** @var \Magento\Framework\Controller\Result\Forward $resultForward */
48-
$resultForward = $this->resultForwardFactory->create();
49-
return $resultForward->forward('noroute');
47+
/** @var \Magento\Framework\Controller\Result\RedirectFactory $resultRedirect */
48+
$resultRedirect = $this->resultRedirectFactory->create();
49+
$resultRedirect->setPath('sales/invoice');
50+
return $resultRedirect;
5051
}
5152

5253
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminGoToCreditmemoViewActionGroup">
12+
<annotations>
13+
<description>Goes to the Order Creditmemo View Page.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="identifier" type="string"/>
17+
</arguments>
18+
19+
<amOnPage url="{{AdminCreditmemoViewPage.url}}/{{identifier}}" stepKey="amOnCreditmemoViewPage"/>
20+
<waitForPageLoad stepKey="waitForPageLoad"/>
21+
</actionGroup>
22+
</actionGroups>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminOpenCreditmemoViewPageWithWrongCreditmemoIdTest">
12+
<annotations>
13+
<stories value="Creditmemo Page With Wrong Creditmemo Id"/>
14+
<title value="Open Creditmemo View Page with Wrong Creditmemo Id"/>
15+
<description value="Open Creditmemo View Page with Wrong Creditmemo Id."/>
16+
<severity value="MAJOR"/>
17+
<group value="sales"/>
18+
</annotations>
19+
20+
<before>
21+
<actionGroup ref="AdminLoginActionGroup" stepKey="LoginAsAdmin"/>
22+
</before>
23+
24+
<after>
25+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
26+
</after>
27+
28+
<actionGroup ref="AdminGoToCreditmemoViewActionGroup" stepKey="navigateOpenCreditmemoViewPage">
29+
<argument name="identifier" value="test"/>
30+
</actionGroup>
31+
32+
<waitForPageLoad stepKey="waitForPageLoad"/>
33+
34+
<seeInCurrentUrl url="{{AdminCreditmemosGridPage.url}}" stepKey="redirectToCreditmemosGridPage"/>
35+
36+
<see selector="{{AdminMessagesSection.error}}" userInput='This creditmemo no longer exists.'
37+
stepKey="seeErrorMessage"/>
38+
</test>
39+
</tests>

app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/ViewTest.php

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\Backend\Model\View\Result\Forward;
1414
use Magento\Backend\Model\View\Result\ForwardFactory;
1515
use Magento\Backend\Model\View\Result\Page;
16+
use Magento\Backend\Model\View\Result\Redirect;
17+
use Magento\Backend\Model\View\Result\RedirectFactory;
1618
use Magento\Framework\App\ActionFlag;
1719
use Magento\Framework\App\Request\Http;
1820
use Magento\Framework\Message\Manager;
@@ -105,6 +107,17 @@ class ViewTest extends TestCase
105107
*/
106108
protected $pageTitleMock;
107109

110+
/**
111+
* @var \Magento\Shipping\Controller\Adminhtml\Order\Creditmemo\View
112+
* @var RedirectFactory|MockObject
113+
*/
114+
protected $resultRedirectFactoryMock;
115+
116+
/**
117+
* @var Redirect|MockObject
118+
*/
119+
protected $resultRedirectMock;
120+
108121
/**
109122
* @var PageFactory|MockObject
110123
*/
@@ -239,7 +252,8 @@ protected function setUp(): void
239252
'context' => $this->contextMock,
240253
'creditmemoLoader' => $this->loaderMock,
241254
'resultPageFactory' => $this->resultPageFactoryMock,
242-
'resultForwardFactory' => $this->resultForwardFactoryMock
255+
'resultForwardFactory' => $this->resultForwardFactoryMock,
256+
'resultRedirectFactory' => $this->resultRedirectFactoryMock
243257
]
244258
);
245259
}
@@ -252,16 +266,11 @@ public function testExecuteNoCreditMemo()
252266
$this->loaderMock->expects($this->once())
253267
->method('load')
254268
->willReturn(false);
255-
$this->resultForwardFactoryMock->expects($this->once())
256-
->method('create')
257-
->willReturn($this->resultForwardMock);
258-
$this->resultForwardMock->expects($this->once())
259-
->method('forward')
260-
->with('noroute')
261-
->willReturnSelf();
262-
269+
270+
$this->prepareRedirect();
271+
$this->setPath('sales/creditmemo');
263272
$this->assertInstanceOf(
264-
Forward::class,
273+
Redirect::class,
265274
$this->controller->execute()
266275
);
267276
}
@@ -322,4 +331,25 @@ public function executeDataProvider()
322331
[$this->invoiceMock]
323332
];
324333
}
334+
335+
/**
336+
* prepareRedirect
337+
*/
338+
protected function prepareRedirect()
339+
{
340+
$this->resultRedirectFactoryMock->expects($this->once())
341+
->method('create')
342+
->willReturn($this->resultRedirectMock);
343+
}
344+
345+
/**
346+
* @param string $path
347+
* @param array $params
348+
*/
349+
protected function setPath($path, $params = [])
350+
{
351+
$this->resultRedirectMock->expects($this->once())
352+
->method('setPath')
353+
->with($path, $params);
354+
}
325355
}

app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/View.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
namespace Magento\Shipping\Controller\Adminhtml\Order\Shipment;
88

99
use Magento\Backend\App\Action;
10+
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
1011

11-
class View extends \Magento\Backend\App\Action
12+
class View extends \Magento\Backend\App\Action implements HttpGetActionInterface
1213
{
1314
/**
1415
* Authorization level of a basic admin session
@@ -71,9 +72,9 @@ public function execute()
7172
$resultPage->getConfig()->getTitle()->prepend("#" . $shipment->getIncrementId());
7273
return $resultPage;
7374
} else {
74-
$resultForward = $this->resultForwardFactory->create();
75-
$resultForward->forward('noroute');
76-
return $resultForward;
75+
$resultRedirect = $this->resultRedirectFactory->create();
76+
$resultRedirect->setPath('sales/shipment');
77+
return $resultRedirect;
7778
}
7879
}
7980
}

app/code/Magento/Shipping/Controller/Adminhtml/Order/ShipmentLoader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ public function load()
110110
$orderId = $this->getOrderId();
111111
$shipmentId = $this->getShipmentId();
112112
if ($shipmentId) {
113-
$shipment = $this->shipmentRepository->get($shipmentId);
113+
try {
114+
$shipment = $this->shipmentRepository->get($shipmentId);
115+
} catch (\Exception $e) {
116+
$this->messageManager->addErrorMessage(__('This shipment no longer exists.'));
117+
return false;
118+
}
114119
} elseif ($orderId) {
115120
$order = $this->orderRepository->get($orderId);
116121

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminGoToShipmentViewActionGroup">
12+
<annotations>
13+
<description>Goes to the Order Shipment View Page.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="identifier" type="string"/>
17+
</arguments>
18+
19+
<amOnPage url="{{AdminShipmentViewPage.url}}/{{identifier}}" stepKey="amOnShipmentViewPage"/>
20+
<waitForPageLoad stepKey="waitForPageLoad"/>
21+
</actionGroup>
22+
</actionGroups>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
11+
<page name="AdminShipmentViewPage" url="sales/shipment/view/shipment_id" area="admin" module="Shipping">
12+
</page>
13+
</pages>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminOpenShipmentViewPageWithWrongShipmentIdTest">
12+
<annotations>
13+
<stories value="Shipment Page With Wrong Shipment Id"/>
14+
<title value="Open Shipment View Page with Wrong Shipment Id"/>
15+
<description value="Open Shipment View Page with Wrong Shipment Id."/>
16+
<severity value="MAJOR"/>
17+
<group value="shipping"/>
18+
</annotations>
19+
20+
<before>
21+
<actionGroup ref="AdminLoginActionGroup" stepKey="LoginAsAdmin"/>
22+
</before>
23+
24+
<after>
25+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
26+
</after>
27+
28+
<actionGroup ref="AdminGoToShipmentViewActionGroup" stepKey="navigateOpenShipmentViewPage">
29+
<argument name="identifier" value="test"/>
30+
</actionGroup>
31+
32+
<waitForPageLoad stepKey="waitForPageLoad"/>
33+
34+
<seeInCurrentUrl url="{{AdminShipmentsGridPage.url}}" stepKey="redirectToShipmentsGridPage"/>
35+
36+
<see selector="{{AdminMessagesSection.error}}" userInput='This shipment no longer exists.'
37+
stepKey="seeErrorMessage"/>
38+
</test>
39+
</tests>

0 commit comments

Comments
 (0)