Skip to content

Commit b39b013

Browse files
author
Dmytro Poperechnyy
committed
MAGETWO-34995: Refactor controllers from the list (Part2)
1 parent b2277a1 commit b39b013

File tree

3 files changed

+65
-41
lines changed

3 files changed

+65
-41
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: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,36 @@
88

99
class Delete extends \Magento\Review\Controller\Adminhtml\Product
1010
{
11+
/**
12+
* @var int
13+
*/
14+
protected $reviewId;
15+
1116
/**
1217
* @return void
1318
*/
1419
public function execute()
1520
{
16-
$reviewId = $this->getRequest()->getParam('id', false);
17-
try {
18-
$this->_reviewFactory->create()->setId($reviewId)->aggregate()->delete();
21+
$this->reviewId = $this->getRequest()->getParam('id', false);
22+
$this->_reviewFactory->create()->setId($this->reviewId)->aggregate()->delete();
1923

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.'));
24+
$this->messageManager->addSuccess(__('The review has been deleted.'));
25+
if ($this->getRequest()->getParam('ret') == 'pending') {
26+
$this->getResponse()->setRedirect($this->getUrl('review/*/pending'));
27+
} else {
28+
$this->getResponse()->setRedirect($this->getUrl('review/*/'));
3129
}
30+
return;
31+
}
3232

33-
$this->_redirect('review/*/edit/', ['id' => $reviewId]);
33+
/**
34+
* {@inheritdoc}
35+
*
36+
* @return \Magento\Backend\Model\View\Result\Redirect
37+
*/
38+
public function getDefaultRedirect()
39+
{
40+
$resultRedirect = $this->resultRedirectFactory->create();
41+
return $resultRedirect->setPath('review/*/edit/', ['id' => $this->reviewId]);
3442
}
3543
}

0 commit comments

Comments
 (0)