Skip to content

Commit 7217c8c

Browse files
author
Dmytro Poperechnyy
committed
Merge remote-tracking branch 'tango/MAGETWO-34995' into MAGETWO-26762
2 parents 0ccf08c + 0246abe commit 7217c8c

File tree

14 files changed

+267
-206
lines changed

14 files changed

+267
-206
lines changed

app/code/Magento/ProductAlert/Controller/Unsubscribe/PriceAll.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,29 @@
99
class PriceAll extends \Magento\ProductAlert\Controller\Unsubscribe
1010
{
1111
/**
12-
* @return void
12+
* @return \Magento\Framework\Controller\Result\Redirect
1313
*/
1414
public function execute()
1515
{
16-
try {
17-
$this->_objectManager->create(
18-
'Magento\ProductAlert\Model\Price'
19-
)->deleteCustomer(
20-
$this->_customerSession->getCustomerId(),
21-
$this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId()
22-
);
23-
$this->messageManager->addSuccess(__('You will no longer receive price alerts for this product.'));
24-
} catch (\Exception $e) {
25-
$this->messageManager->addException($e, __('Unable to update the alert subscription.'));
26-
}
27-
$this->_redirect('customer/account/');
16+
$this->_objectManager->create(
17+
'Magento\ProductAlert\Model\Price'
18+
)->deleteCustomer(
19+
$this->_customerSession->getCustomerId(),
20+
$this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId()
21+
);
22+
$this->messageManager->addSuccess(__('You will no longer receive price alerts for this product.'));
23+
24+
return $this->getDefaultRedirect();
25+
}
26+
27+
/**
28+
* {@inheritdoc}
29+
*
30+
* @return \Magento\Framework\Controller\Result\Redirect
31+
*/
32+
public function getDefaultRedirect()
33+
{
34+
$resultRedirect = $this->resultRedirectFactory->create();
35+
return $resultRedirect->setPath('customer/account/');
2836
}
2937
}

app/code/Magento/ProductAlert/Controller/Unsubscribe/StockAll.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,29 @@
99
class StockAll extends \Magento\ProductAlert\Controller\Unsubscribe
1010
{
1111
/**
12-
* @return void
12+
* @return \Magento\Framework\Controller\Result\Redirect
1313
*/
1414
public function execute()
1515
{
16-
try {
17-
$this->_objectManager->create(
18-
'Magento\ProductAlert\Model\Stock'
19-
)->deleteCustomer(
20-
$this->_customerSession->getCustomerId(),
21-
$this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId()
22-
);
23-
$this->messageManager->addSuccess(__('You will no longer receive stock alerts.'));
24-
} catch (\Exception $e) {
25-
$this->messageManager->addException($e, __('Unable to update the alert subscription.'));
26-
}
27-
$this->_redirect('customer/account/');
16+
$this->_objectManager->create(
17+
'Magento\ProductAlert\Model\Stock'
18+
)->deleteCustomer(
19+
$this->_customerSession->getCustomerId(),
20+
$this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId()
21+
);
22+
$this->messageManager->addSuccess(__('You will no longer receive stock alerts.'));
23+
24+
return $this->getDefaultRedirect();
25+
}
26+
27+
/**
28+
* {@inheritdoc}
29+
*
30+
* @return \Magento\Framework\Controller\Result\Redirect
31+
*/
32+
public function getDefaultRedirect()
33+
{
34+
$resultRedirect = $this->resultRedirectFactory->create();
35+
return $resultRedirect->setPath('customer/account/');
2836
}
2937
}

app/code/Magento/Review/Controller/Adminhtml/Product/Delete.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,24 @@ class Delete extends \Magento\Review\Controller\Adminhtml\Product
1414
public function execute()
1515
{
1616
$reviewId = $this->getRequest()->getParam('id', false);
17-
try {
18-
$this->_reviewFactory->create()->setId($reviewId)->aggregate()->delete();
17+
$this->_reviewFactory->create()->setId($reviewId)->aggregate()->delete();
1918

20-
$this->messageManager->addSuccess(__('The review has been deleted.'));
21-
if ($this->getRequest()->getParam('ret') == 'pending') {
22-
$this->getResponse()->setRedirect($this->getUrl('review/*/pending'));
23-
} else {
24-
$this->getResponse()->setRedirect($this->getUrl('review/*/'));
25-
}
26-
return;
27-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
28-
$this->messageManager->addError($e->getMessage());
29-
} catch (\Exception $e) {
30-
$this->messageManager->addException($e, __('Something went wrong deleting this review.'));
19+
$this->messageManager->addSuccess(__('The review has been deleted.'));
20+
if ($this->getRequest()->getParam('ret') == 'pending') {
21+
$this->getResponse()->setRedirect($this->getUrl('review/*/pending'));
22+
} else {
23+
$this->getResponse()->setRedirect($this->getUrl('review/*/'));
3124
}
25+
}
3226

33-
$this->_redirect('review/*/edit/', ['id' => $reviewId]);
27+
/**
28+
* {@inheritdoc}
29+
*
30+
* @return \Magento\Backend\Model\View\Result\Redirect
31+
*/
32+
public function getDefaultRedirect()
33+
{
34+
$resultRedirect = $this->resultRedirectFactory->create();
35+
return $resultRedirect->setPath('review/*/edit/', ['id' => $this->getRequest()->getParam('id', false)]);
3436
}
3537
}

app/code/Magento/Sales/Controller/Adminhtml/Transactions/Fetch.php

100644100755
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
namespace Magento\Sales\Controller\Adminhtml\Transactions;
88

99
use Magento\Backend\App\Action;
10-
use Magento\Backend\Model\View\Result\Redirect;
1110

1211
class Fetch extends \Magento\Sales\Controller\Adminhtml\Transactions
1312
{
1413
/**
1514
* Fetch transaction details action
1615
*
17-
* @return Redirect
16+
* @return \Magento\Backend\Model\View\Result\Redirect
1817
*/
1918
public function execute()
2019
{
@@ -24,16 +23,18 @@ public function execute()
2423
if (!$txn) {
2524
return $resultRedirect->setPath('sales/*/');
2625
}
27-
try {
28-
$txn->getOrderPaymentObject()->setOrder($txn->getOrder())->importTransactionInfo($txn);
29-
$txn->save();
30-
$this->messageManager->addSuccess(__('The transaction details have been updated.'));
31-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
32-
$this->messageManager->addError($e->getMessage());
33-
} catch (\Exception $e) {
34-
$this->messageManager->addError(__('We can\'t update the transaction details.'));
35-
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
36-
}
26+
$txn->getOrderPaymentObject()->setOrder($txn->getOrder())->importTransactionInfo($txn);
27+
$txn->save();
28+
$this->messageManager->addSuccess(__('The transaction details have been updated.'));
29+
return $this->getDefaultRedirect();
30+
}
31+
32+
/**
33+
* @return \Magento\Backend\Model\View\Result\Redirect
34+
*/
35+
public function getDefaultRedirect()
36+
{
37+
$resultRedirect = $this->resultRedirectFactory->create();
3738
return $resultRedirect->setPath('sales/transactions/view', ['_current' => true]);
3839
}
3940
}

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

100644100755
Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,32 @@ protected function _isAllowed()
4545
/**
4646
* Send email with shipment data to customer
4747
*
48-
* @return void
48+
* @return \Magento\Backend\Model\View\Result\Redirect
4949
*/
5050
public function execute()
5151
{
52-
try {
53-
$this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
54-
$this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
55-
$this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment'));
56-
$this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
57-
$shipment = $this->shipmentLoader->load();
58-
if ($shipment) {
59-
$this->_objectManager->create('Magento\Shipping\Model\ShipmentNotifier')
60-
->notify($shipment);
61-
$shipment->save();
62-
$this->messageManager->addSuccess(__('You sent the shipment.'));
63-
}
64-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
65-
$this->messageManager->addError($e->getMessage());
66-
} catch (\Exception $e) {
67-
$this->messageManager->addError(__('Cannot send shipment information.'));
52+
$this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
53+
$this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
54+
$this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment'));
55+
$this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
56+
$shipment = $this->shipmentLoader->load();
57+
if ($shipment) {
58+
$this->_objectManager->create('Magento\Shipping\Model\ShipmentNotifier')
59+
->notify($shipment);
60+
$shipment->save();
61+
$this->messageManager->addSuccess(__('You sent the shipment.'));
6862
}
69-
$this->_redirect('*/*/view', ['shipment_id' => $this->getRequest()->getParam('shipment_id')]);
63+
return $this->getDefaultRedirect();
64+
}
65+
66+
/**
67+
* @inheritdoc
68+
*
69+
* @return \Magento\Backend\Model\View\Result\Redirect
70+
*/
71+
public function getDefaultRedirect()
72+
{
73+
$resultRedirect = $this->resultRedirectFactory->create();
74+
return $resultRedirect->setPath('*/*/view', ['shipment_id' => $this->getRequest()->getParam('shipment_id')]);
7075
}
7176
}

app/code/Magento/Shipping/Test/Unit/Controller/Adminhtml/Order/Shipment/EmailTest.php

100644100755
Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Class EmailTest
1616
*
1717
* @package Magento\Shipping\Controller\Adminhtml\Order\Shipment
18+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1819
*/
1920
class EmailTest extends \PHPUnit_Framework_TestCase
2021
{
@@ -63,6 +64,16 @@ class EmailTest extends \PHPUnit_Framework_TestCase
6364
*/
6465
protected $helper;
6566

67+
/**
68+
* @var \Magento\Backend\Model\View\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject
69+
*/
70+
protected $resultRedirectFactory;
71+
72+
/**
73+
* @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject
74+
*/
75+
protected $resultRedirect;
76+
6677
/**
6778
* @var \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader|\PHPUnit_Framework_MockObject_MockObject
6879
*/
@@ -88,7 +99,8 @@ public function setUp()
8899
'getObjectManager',
89100
'getSession',
90101
'getActionFlag',
91-
'getHelper'
102+
'getHelper',
103+
'getResultRedirectFactory'
92104
],
93105
[],
94106
'',
@@ -129,27 +141,27 @@ public function setUp()
129141
$this->session = $this->getMock('Magento\Backend\Model\Session', ['setIsUrlNotice'], [], '', false);
130142
$this->actionFlag = $this->getMock('Magento\Framework\App\ActionFlag', ['get'], [], '', false);
131143
$this->helper = $this->getMock('\Magento\Backend\Helper\Data', ['getUrl'], [], '', false);
144+
$this->resultRedirect = $this->getMock('Magento\Backend\Model\View\Result\Redirect', [], [], '', false);
145+
$this->resultRedirectFactory = $this->getMock(
146+
'Magento\Backend\Model\View\Result\RedirectFactory',
147+
['create'],
148+
[],
149+
'',
150+
false
151+
);
152+
$this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
153+
154+
$this->context->expects($this->once())->method('getMessageManager')->willReturn($this->messageManager);
155+
$this->context->expects($this->once())->method('getRequest')->willReturn($this->request);
156+
$this->context->expects($this->once())->method('getResponse')->willReturn($this->response);
157+
$this->context->expects($this->once())->method('getObjectManager')->willReturn($this->objectManager);
158+
$this->context->expects($this->once())->method('getSession')->willReturn($this->session);
159+
$this->context->expects($this->once())->method('getActionFlag')->willReturn($this->actionFlag);
160+
$this->context->expects($this->once())->method('getHelper')->willReturn($this->helper);
132161
$this->context->expects($this->once())
133-
->method('getMessageManager')
134-
->will($this->returnValue($this->messageManager));
135-
$this->context->expects($this->once())
136-
->method('getRequest')
137-
->will($this->returnValue($this->request));
138-
$this->context->expects($this->once())
139-
->method('getResponse')
140-
->will($this->returnValue($this->response));
141-
$this->context->expects($this->once())
142-
->method('getObjectManager')
143-
->will($this->returnValue($this->objectManager));
144-
$this->context->expects($this->once())
145-
->method('getSession')
146-
->will($this->returnValue($this->session));
147-
$this->context->expects($this->once())
148-
->method('getActionFlag')
149-
->will($this->returnValue($this->actionFlag));
150-
$this->context->expects($this->once())
151-
->method('getHelper')
152-
->will($this->returnValue($this->helper));
162+
->method('getResultRedirectFactory')
163+
->willReturn($this->resultRedirectFactory);
164+
153165
$this->shipmentEmail = $objectManagerHelper->getObject(
154166
'Magento\Shipping\Controller\Adminhtml\Order\Shipment\Email',
155167
[
@@ -240,14 +252,8 @@ protected function prepareRedirect($path, $arguments, $index)
240252
$this->session->expects($this->any())
241253
->method('setIsUrlNotice')
242254
->with(true);
243-
244-
$url = $path . '/' . (!empty($arguments) ? $arguments['shipment_id'] : '');
245-
$this->helper->expects($this->at($index))
246-
->method('getUrl')
247-
->with($path, $arguments)
248-
->will($this->returnValue($url));
249-
$this->response->expects($this->at($index))
250-
->method('setRedirect')
251-
->with($url);
255+
$this->resultRedirect->expects($this->at($index))
256+
->method('setPath')
257+
->with($path, ['shipment_id' => $arguments['shipment_id']]);
252258
}
253259
}

app/code/Magento/Tax/Controller/Adminhtml/Rate/Delete.php

100644100755
Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Delete extends \Magento\Tax\Controller\Adminhtml\Rate
1313
/**
1414
* Delete Rate and Data
1515
*
16-
* @return void
16+
* @return \Magento\Backend\Model\View\Result\Redirect|void
1717
*/
1818
public function execute()
1919
{
@@ -29,17 +29,25 @@ public function execute()
2929
__('Something went wrong deleting this rate because of an incorrect rate ID.')
3030
);
3131
$this->getResponse()->setRedirect($this->getUrl('tax/*/'));
32-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
33-
$this->messageManager->addError($e->getMessage());
34-
} catch (\Exception $e) {
35-
$this->messageManager->addError(__('Something went wrong deleting this rate.'));
32+
return;
3633
}
34+
return $this->getDefaultRedirect();
35+
}
36+
}
3737

38-
if ($referer = $this->getRequest()->getServer('HTTP_REFERER')) {
39-
$this->getResponse()->setRedirect($referer);
40-
} else {
41-
$this->getResponse()->setRedirect($this->getUrl("*/*/"));
42-
}
38+
/**
39+
* @inheritdoc
40+
*
41+
* @return \Magento\Backend\Model\View\Result\Redirect
42+
*/
43+
public function getDefaultRedirect()
44+
{
45+
$resultRedirect = $this->resultRedirectFactory->create();
46+
if ($this->getRequest()->getServer('HTTP_REFERER')) {
47+
$resultRedirect->setRefererUrl();
48+
} else {
49+
$resultRedirect->setUrl($this->getUrl("*/*/"));
4350
}
51+
return $resultRedirect;
4452
}
4553
}

0 commit comments

Comments
 (0)