6
6
7
7
namespace Magento \ProductAlert \Controller \Add ;
8
8
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 ;
14
9
use Magento \Catalog \Api \ProductRepositoryInterface ;
15
- use Magento \Framework \ UrlInterface ;
10
+ use Magento \Customer \ Model \ Session as CustomerSession ;
16
11
use Magento \Framework \App \Action \Action ;
12
+ use Magento \Framework \App \Action \Context ;
13
+ use Magento \Framework \App \Action \HttpGetActionInterface ;
17
14
use Magento \Framework \Controller \ResultFactory ;
15
+ use Magento \Framework \Controller \Result \Redirect ;
18
16
use Magento \Framework \Exception \NoSuchEntityException ;
17
+ use Magento \Framework \UrlInterface ;
18
+ use Magento \ProductAlert \Controller \Add as AddController ;
19
+ use Magento \Store \Model \StoreManagerInterface ;
19
20
20
21
/**
21
22
* Controller for notifying about price.
@@ -28,15 +29,17 @@ class Price extends AddController implements HttpGetActionInterface
28
29
protected $ storeManager ;
29
30
30
31
/**
31
- * @var \Magento\Catalog\Api\ProductRepositoryInterface
32
+ * @var \Magento\Catalog\Api\ProductRepositoryInterface
32
33
*/
33
34
protected $ productRepository ;
34
35
35
36
/**
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
40
43
*/
41
44
public function __construct (
42
45
Context $ context ,
@@ -54,6 +57,7 @@ public function __construct(
54
57
*
55
58
* @param string $url
56
59
* @return bool
60
+ * @throws NoSuchEntityException
57
61
*/
58
62
protected function isInternal ($ url )
59
63
{
@@ -68,13 +72,14 @@ protected function isInternal($url)
68
72
/**
69
73
* Method for adding info about product alert price.
70
74
*
71
- * @return \Magento\Framework\Controller\Result\Redirect
75
+ * @return \Magento\Framework\Controller\ResultInterface
76
+ * @throws NoSuchEntityException
72
77
*/
73
78
public function execute ()
74
79
{
75
80
$ backUrl = $ this ->getRequest ()->getParam (Action::PARAM_NAME_URL_ENCODED );
76
81
$ productId = (int )$ this ->getRequest ()->getParam ('product_id ' );
77
- /** @var \Magento\Framework\Controller\Result\ Redirect $resultRedirect */
82
+ /** @var Redirect $resultRedirect */
78
83
$ resultRedirect = $ this ->resultFactory ->create (ResultFactory::TYPE_REDIRECT );
79
84
if (!$ backUrl || !$ productId ) {
80
85
$ resultRedirect ->setPath ('/ ' );
@@ -93,17 +98,17 @@ public function execute()
93
98
->setWebsiteId ($ store ->getWebsiteId ())
94
99
->setStoreId ($ store ->getId ());
95
100
$ model ->save ();
96
- $ this ->messageManager ->addSuccess (__ ('You saved the alert subscription. ' ));
101
+ $ this ->messageManager ->addSuccessMessage (__ ('You saved the alert subscription. ' ));
97
102
} catch (NoSuchEntityException $ noEntityException ) {
98
- $ this ->messageManager ->addError (__ ('There are not enough parameters. ' ));
103
+ $ this ->messageManager ->addErrorMessage (__ ('There are not enough parameters. ' ));
99
104
if ($ this ->isInternal ($ backUrl )) {
100
105
$ resultRedirect ->setUrl ($ backUrl );
101
106
} else {
102
107
$ resultRedirect ->setPath ('/ ' );
103
108
}
104
109
return $ resultRedirect ;
105
110
} catch (\Exception $ e ) {
106
- $ this ->messageManager ->addException (
111
+ $ this ->messageManager ->addExceptionMessage (
107
112
$ e ,
108
113
__ ("The alert subscription couldn't update at this time. Please try again later. " )
109
114
);
0 commit comments