Skip to content

Commit 8285e6a

Browse files
committed
magento/magento2#: Replace deprecated message functions in the Magento_ProductAlert module.
1 parent 32305e0 commit 8285e6a

File tree

4 files changed

+43
-27
lines changed

4 files changed

+43
-27
lines changed

app/code/Magento/ProductAlert/Controller/Add/Price.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66

77
namespace Magento\ProductAlert\Controller\Add;
88

9-
use Magento\Framework\App\Action\HttpGetActionInterface;
10-
use Magento\ProductAlert\Controller\Add as AddController;
11-
use Magento\Framework\App\Action\Context;
12-
use Magento\Customer\Model\Session as CustomerSession;
13-
use Magento\Store\Model\StoreManagerInterface;
149
use Magento\Catalog\Api\ProductRepositoryInterface;
15-
use Magento\Framework\UrlInterface;
10+
use Magento\Customer\Model\Session as CustomerSession;
1611
use Magento\Framework\App\Action\Action;
12+
use Magento\Framework\App\Action\Context;
13+
use Magento\Framework\App\Action\HttpGetActionInterface;
1714
use Magento\Framework\Controller\ResultFactory;
15+
use Magento\Framework\Controller\Result\Redirect;
1816
use Magento\Framework\Exception\NoSuchEntityException;
17+
use Magento\Framework\UrlInterface;
18+
use Magento\ProductAlert\Controller\Add as AddController;
19+
use Magento\Store\Model\StoreManagerInterface;
1920

2021
/**
2122
* Controller for notifying about price.
@@ -28,15 +29,17 @@ class Price extends AddController implements HttpGetActionInterface
2829
protected $storeManager;
2930

3031
/**
31-
* @var \Magento\Catalog\Api\ProductRepositoryInterface
32+
* @var \Magento\Catalog\Api\ProductRepositoryInterface
3233
*/
3334
protected $productRepository;
3435

3536
/**
36-
* @param \Magento\Framework\App\Action\Context $context
37-
* @param \Magento\Customer\Model\Session $customerSession
38-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
39-
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
37+
* Price constructor.
38+
*
39+
* @param Context $context
40+
* @param CustomerSession $customerSession
41+
* @param StoreManagerInterface $storeManager
42+
* @param ProductRepositoryInterface $productRepository
4043
*/
4144
public function __construct(
4245
Context $context,
@@ -54,6 +57,7 @@ public function __construct(
5457
*
5558
* @param string $url
5659
* @return bool
60+
* @throws NoSuchEntityException
5761
*/
5862
protected function isInternal($url)
5963
{
@@ -68,13 +72,14 @@ protected function isInternal($url)
6872
/**
6973
* Method for adding info about product alert price.
7074
*
71-
* @return \Magento\Framework\Controller\Result\Redirect
75+
* @return \Magento\Framework\Controller\ResultInterface
76+
* @throws NoSuchEntityException
7277
*/
7378
public function execute()
7479
{
7580
$backUrl = $this->getRequest()->getParam(Action::PARAM_NAME_URL_ENCODED);
7681
$productId = (int)$this->getRequest()->getParam('product_id');
77-
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
82+
/** @var Redirect $resultRedirect */
7883
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
7984
if (!$backUrl || !$productId) {
8085
$resultRedirect->setPath('/');
@@ -93,17 +98,17 @@ public function execute()
9398
->setWebsiteId($store->getWebsiteId())
9499
->setStoreId($store->getId());
95100
$model->save();
96-
$this->messageManager->addSuccess(__('You saved the alert subscription.'));
101+
$this->messageManager->addSuccessMessage(__('You saved the alert subscription.'));
97102
} catch (NoSuchEntityException $noEntityException) {
98-
$this->messageManager->addError(__('There are not enough parameters.'));
103+
$this->messageManager->addErrorMessage(__('There are not enough parameters.'));
99104
if ($this->isInternal($backUrl)) {
100105
$resultRedirect->setUrl($backUrl);
101106
} else {
102107
$resultRedirect->setPath('/');
103108
}
104109
return $resultRedirect;
105110
} catch (\Exception $e) {
106-
$this->messageManager->addException(
111+
$this->messageManager->addExceptionMessage(
107112
$e,
108113
__("The alert subscription couldn't update at this time. Please try again later.")
109114
);

app/code/Magento/ProductAlert/Controller/Add/Stock.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ public function execute()
7676
->setWebsiteId($store->getWebsiteId())
7777
->setStoreId($store->getId());
7878
$model->save();
79-
$this->messageManager->addSuccess(__('Alert subscription has been saved.'));
79+
$this->messageManager->addSuccessMessage(__('Alert subscription has been saved.'));
8080
} catch (NoSuchEntityException $noEntityException) {
81-
$this->messageManager->addError(__('There are not enough parameters.'));
81+
$this->messageManager->addErrorMessage(__('There are not enough parameters.'));
8282
$resultRedirect->setUrl($backUrl);
8383
return $resultRedirect;
8484
} catch (\Exception $e) {
85-
$this->messageManager->addException(
85+
$this->messageManager->addExceptionMessage(
8686
$e,
8787
__("The alert subscription couldn't update at this time. Please try again later.")
8888
);

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66

77
namespace Magento\ProductAlert\Controller\Unsubscribe;
88

9+
use Magento\Framework\App\Action\HttpGetActionInterface;
910
use Magento\ProductAlert\Controller\Unsubscribe as UnsubscribeController;
1011
use Magento\Framework\App\Action\Context;
1112
use Magento\Customer\Model\Session as CustomerSession;
1213
use Magento\Catalog\Api\ProductRepositoryInterface;
1314
use Magento\Framework\Controller\ResultFactory;
1415
use Magento\Framework\Exception\NoSuchEntityException;
1516

16-
class Price extends UnsubscribeController
17+
/**
18+
* Class Price
19+
*/
20+
class Price extends UnsubscribeController implements HttpGetActionInterface
1721
{
1822
/**
1923
* @var \Magento\Catalog\Api\ProductRepositoryInterface
@@ -35,6 +39,8 @@ public function __construct(
3539
}
3640

3741
/**
42+
* Unsubscribe action
43+
*
3844
* @return \Magento\Framework\Controller\Result\Redirect
3945
*/
4046
public function execute()
@@ -51,8 +57,13 @@ public function execute()
5157
/* @var $product \Magento\Catalog\Model\Product */
5258
$product = $this->productRepository->getById($productId);
5359
if (!$product->isVisibleInCatalog()) {
54-
throw new NoSuchEntityException();
60+
$this->messageManager->addErrorMessage(
61+
__("The product wasn't found. Verify the product and try again.")
62+
);
63+
$resultRedirect->setPath('customer/account/');
64+
return $resultRedirect;
5565
}
66+
5667
/** @var \Magento\ProductAlert\Model\Price $model */
5768
$model = $this->_objectManager->create(\Magento\ProductAlert\Model\Price::class)
5869
->setCustomerId($this->customerSession->getCustomerId())
@@ -67,13 +78,13 @@ public function execute()
6778
$model->delete();
6879
}
6980

70-
$this->messageManager->addSuccess(__('You deleted the alert subscription.'));
81+
$this->messageManager->addSuccessMessage(__('You deleted the alert subscription.'));
7182
} catch (NoSuchEntityException $noEntityException) {
72-
$this->messageManager->addError(__("The product wasn't found. Verify the product and try again."));
83+
$this->messageManager->addErrorMessage(__("The product wasn't found. Verify the product and try again."));
7384
$resultRedirect->setPath('customer/account/');
7485
return $resultRedirect;
7586
} catch (\Exception $e) {
76-
$this->messageManager->addException(
87+
$this->messageManager->addExceptionMessage(
7788
$e,
7889
__("The alert subscription couldn't update at this time. Please try again later.")
7990
);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ public function execute()
9494
if ($model->getId()) {
9595
$model->delete();
9696
}
97-
$this->messageManager->addSuccess(__('You will no longer receive stock alerts for this product.'));
97+
$this->messageManager->addSuccessMessage(__('You will no longer receive stock alerts for this product.'));
9898
} catch (NoSuchEntityException $noEntityException) {
99-
$this->messageManager->addError(__('The product was not found.'));
99+
$this->messageManager->addErrorMessage(__('The product was not found.'));
100100
$resultRedirect->setPath('customer/account/');
101101
return $resultRedirect;
102102
} catch (\Exception $e) {
103-
$this->messageManager->addException(
103+
$this->messageManager->addExceptionMessage(
104104
$e,
105105
__("The alert subscription couldn't update at this time. Please try again later.")
106106
);

0 commit comments

Comments
 (0)