1
1
<?php
2
2
/**
3
- *
4
3
* Copyright © 2015 Magento. All rights reserved.
5
4
* See COPYING.txt for license details.
6
5
*/
10
9
namespace Magento \Sendfriend \Controller \Product ;
11
10
12
11
use Magento \Framework \Exception \NoSuchEntityException ;
12
+ use Magento \Framework \Controller \ResultFactory ;
13
13
14
14
class Sendmail extends \Magento \Sendfriend \Controller \Product
15
15
{
@@ -39,22 +39,27 @@ public function __construct(
39
39
/**
40
40
* Send Email Post Action
41
41
*
42
- * @return void
42
+ * @return \Magento\Framework\Controller\ResultInterface
43
43
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
44
44
*/
45
45
public function execute ()
46
46
{
47
+ /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
48
+ $ resultRedirect = $ this ->resultFactory ->create (ResultFactory::TYPE_REDIRECT );
49
+
47
50
if (!$ this ->_formKeyValidator ->validate ($ this ->getRequest ())) {
48
- $ this -> _redirect ('sendfriend/product/send ' , ['_current ' => true ]);
49
- return ;
51
+ $ resultRedirect -> setPath ('sendfriend/product/send ' , ['_current ' => true ]);
52
+ return $ resultRedirect ;
50
53
}
51
54
52
55
$ product = $ this ->_initProduct ();
53
56
$ data = $ this ->getRequest ()->getPostValue ();
54
57
55
58
if (!$ product || !$ data ) {
56
- $ this ->_forward ('noroute ' );
57
- return ;
59
+ /** @var \Magento\Framework\Controller\Result\Forward $resultForward */
60
+ $ resultForward = $ this ->resultFactory ->create (ResultFactory::TYPE_FORWARD );
61
+ $ resultForward ->forward ('noroute ' );
62
+ return $ resultForward ;
58
63
}
59
64
60
65
$ categoryId = $ this ->getRequest ()->getParam ('cat_id ' , null );
@@ -82,8 +87,8 @@ public function execute()
82
87
$ this ->sendFriend ->send ();
83
88
$ this ->messageManager ->addSuccess (__ ('The link to a friend was sent. ' ));
84
89
$ url = $ product ->getProductUrl ();
85
- $ this -> getResponse ()-> setRedirect ($ this ->_redirect ->success ($ url ));
86
- return ;
90
+ $ resultRedirect -> setUrl ($ this ->_redirect ->success ($ url ));
91
+ return $ resultRedirect ;
87
92
} else {
88
93
if (is_array ($ validate )) {
89
94
foreach ($ validate as $ errorMessage ) {
@@ -103,6 +108,7 @@ public function execute()
103
108
$ catalogSession ->setSendfriendFormData ($ data );
104
109
105
110
$ url = $ this ->_url ->getUrl ('sendfriend/product/send ' , ['_current ' => true ]);
106
- $ this ->getResponse ()->setRedirect ($ this ->_redirect ->error ($ url ));
111
+ $ resultRedirect ->setUrl ($ this ->_redirect ->error ($ url ));
112
+ return $ resultRedirect ;
107
113
}
108
114
}
0 commit comments