6
6
namespace Magento \Wishlist \Controller \Index ;
7
7
8
8
use Magento \Catalog \Api \ProductRepositoryInterface ;
9
- use Magento \Framework \App \Action ;
9
+ use Magento \Customer \Model \Session ;
10
+ use Magento \Framework \App \Action \Context ;
10
11
use Magento \Framework \App \Action \HttpPostActionInterface ;
12
+ use Magento \Framework \Controller \Result \Redirect ;
11
13
use Magento \Framework \Data \Form \FormKey \Validator ;
14
+ use Magento \Framework \Exception \LocalizedException ;
12
15
use Magento \Framework \Exception \NotFoundException ;
13
16
use Magento \Framework \Exception \NoSuchEntityException ;
14
17
use Magento \Framework \Controller \ResultFactory ;
15
18
use Magento \Framework \App \ObjectManager ;
16
19
use Magento \Framework \UrlInterface ;
17
20
use Magento \Framework \App \Response \RedirectInterface ;
21
+ use Magento \Framework \Controller \ResultInterface ;
22
+ use Magento \Wishlist \Controller \WishlistProviderInterface ;
18
23
19
24
/**
20
25
* Wish list Add controller
24
29
class Add extends \Magento \Wishlist \Controller \AbstractIndex implements HttpPostActionInterface
25
30
{
26
31
/**
27
- * @var \Magento\Wishlist\Controller\ WishlistProviderInterface
32
+ * @var WishlistProviderInterface
28
33
*/
29
34
protected $ wishlistProvider ;
30
35
31
36
/**
32
- * @var \Magento\Customer\Model\ Session
37
+ * @var Session
33
38
*/
34
39
protected $ _customerSession ;
35
40
@@ -43,23 +48,29 @@ class Add extends \Magento\Wishlist\Controller\AbstractIndex implements HttpPost
43
48
*/
44
49
protected $ formKeyValidator ;
45
50
51
+ /**
52
+ * @var RedirectInterface
53
+ */
46
54
private $ redirect ;
47
55
56
+ /**
57
+ * @var mixed UrlInterface
58
+ */
48
59
private $ urlBuilder ;
49
60
50
61
/**
51
- * @param Action\ Context $context
52
- * @param \Magento\Customer\Model\ Session $customerSession
53
- * @param \Magento\Wishlist\Controller\ WishlistProviderInterface $wishlistProvider
62
+ * @param Context $context
63
+ * @param Session $customerSession
64
+ * @param WishlistProviderInterface $wishlistProvider
54
65
* @param ProductRepositoryInterface $productRepository
55
66
* @param Validator $formKeyValidator
56
- * @param RedirectInterface $redirect
57
- * @param UrlInterface $urlBuilder
67
+ * @param RedirectInterface|null $redirect
68
+ * @param UrlInterface|null $urlBuilder
58
69
*/
59
70
public function __construct (
60
- Action \ Context $ context ,
61
- \ Magento \ Customer \ Model \ Session $ customerSession ,
62
- \ Magento \ Wishlist \ Controller \ WishlistProviderInterface $ wishlistProvider ,
71
+ Context $ context ,
72
+ Session $ customerSession ,
73
+ WishlistProviderInterface $ wishlistProvider ,
63
74
ProductRepositoryInterface $ productRepository ,
64
75
Validator $ formKeyValidator ,
65
76
RedirectInterface $ redirect = null ,
@@ -75,15 +86,17 @@ public function __construct(
75
86
}
76
87
77
88
/**
78
- * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface
89
+ * Adding new item
90
+ *
91
+ * @return ResultInterface
79
92
* @throws NotFoundException
80
93
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
81
94
* @SuppressWarnings(PHPMD.NPathComplexity)
82
95
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
83
96
*/
84
97
public function execute ()
85
98
{
86
- /** @var \Magento\Framework\Controller\Result\ Redirect $resultRedirect */
99
+ /** @var Redirect $resultRedirect */
87
100
$ resultRedirect = $ this ->resultFactory ->create (ResultFactory::TYPE_REDIRECT );
88
101
if (!$ this ->formKeyValidator ->validate ($ this ->getRequest ())) {
89
102
return $ resultRedirect ->setPath ('*/ ' );
@@ -126,7 +139,7 @@ public function execute()
126
139
127
140
$ result = $ wishlist ->addNewItem ($ product , $ buyRequest );
128
141
if (is_string ($ result )) {
129
- throw new \ Magento \ Framework \ Exception \ LocalizedException (__ ($ result ));
142
+ throw new LocalizedException (__ ($ result ));
130
143
}
131
144
if ($ wishlist ->isObjectNew ()) {
132
145
$ wishlist ->save ();
@@ -153,7 +166,7 @@ public function execute()
153
166
]
154
167
);
155
168
// phpcs:disable Magento2.Exceptions.ThrowCatch
156
- } catch (\ Magento \ Framework \ Exception \ LocalizedException $ e ) {
169
+ } catch (LocalizedException $ e ) {
157
170
$ this ->messageManager ->addErrorMessage (
158
171
__ ('We can \'t add the item to Wish List right now: %1. ' , $ e ->getMessage ())
159
172
);
0 commit comments