8
8
9
9
use Magento \Framework \App \Action ;
10
10
use Magento \Framework \Exception \NotFoundException ;
11
- use Magento \Framework \App \ResponseInterface ;
12
11
use Magento \Wishlist \Controller \IndexInterface ;
12
+ use Magento \Framework \Controller \ResultFactory ;
13
+ use Magento \Framework \View \Result \Layout as ResultLayout ;
13
14
14
15
/**
15
16
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -84,16 +85,19 @@ public function __construct(
84
85
/**
85
86
* Share wishlist
86
87
*
87
- * @return ResponseInterface|void
88
+ * @return \Magento\Framework\Controller\Result\Redirect
88
89
* @throws NotFoundException
89
90
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
90
91
* @SuppressWarnings(PHPMD.NPathComplexity)
91
92
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
92
93
*/
93
94
public function execute ()
94
95
{
96
+ /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
97
+ $ resultRedirect = $ this ->resultFactory ->create (ResultFactory::TYPE_REDIRECT );
95
98
if (!$ this ->_formKeyValidator ->validate ($ this ->getRequest ())) {
96
- return $ this ->_redirect ('*/*/ ' );
99
+ $ resultRedirect ->setPath ('*/*/ ' );
100
+ return $ resultRedirect ;
97
101
}
98
102
99
103
$ wishlist = $ this ->wishlistProvider ->getWishlist ();
@@ -136,11 +140,12 @@ public function execute()
136
140
)->setSharingForm (
137
141
$ this ->getRequest ()->getPostValue ()
138
142
);
139
- $ this -> _redirect ('*/*/share ' );
140
- return ;
143
+ $ resultRedirect -> setPath ('*/*/share ' );
144
+ return $ resultRedirect ;
141
145
}
142
-
143
- $ this ->addLayoutHandles ();
146
+ /** @var \Magento\Framework\View\Result\Layout $resultLayout */
147
+ $ resultLayout = $ this ->resultFactory ->create (ResultFactory::TYPE_LAYOUT );
148
+ $ this ->addLayoutHandles ($ resultLayout );
144
149
$ this ->inlineTranslation ->suspend ();
145
150
146
151
$ sent = 0 ;
@@ -149,7 +154,7 @@ public function execute()
149
154
$ customer = $ this ->_customerSession ->getCustomerDataObject ();
150
155
$ customerName = $ this ->_customerHelperView ->getCustomerName ($ customer );
151
156
152
- $ message .= $ this ->getRssLink ($ wishlist ->getId ());
157
+ $ message .= $ this ->getRssLink ($ wishlist ->getId (), $ resultLayout );
153
158
$ emails = array_unique ($ emails );
154
159
$ sharingCode = $ wishlist ->getSharingCode ();
155
160
@@ -172,7 +177,7 @@ public function execute()
172
177
'customer ' => $ customer ,
173
178
'customerName ' => $ customerName ,
174
179
'salable ' => $ wishlist ->isSalable () ? 'yes ' : '' ,
175
- 'items ' => $ this ->getWishlistItems (),
180
+ 'items ' => $ this ->getWishlistItems ($ resultLayout ),
176
181
'addAllLink ' => $ this ->_url ->getUrl ('*/shared/allcart ' , ['code ' => $ sharingCode ]),
177
182
'viewOnSiteLink ' => $ this ->_url ->getUrl ('*/shared/index ' , ['code ' => $ sharingCode ]),
178
183
'message ' => $ message ,
@@ -203,7 +208,8 @@ public function execute()
203
208
204
209
$ this ->_eventManager ->dispatch ('wishlist_share ' , ['wishlist ' => $ wishlist ]);
205
210
$ this ->messageManager ->addSuccess (__ ('Your wish list has been shared. ' ));
206
- $ this ->_redirect ('*/* ' , ['wishlist_id ' => $ wishlist ->getId ()]);
211
+ $ resultRedirect ->setPath ('*/* ' , ['wishlist_id ' => $ wishlist ->getId ()]);
212
+ return $ resultRedirect ;
207
213
} catch (\Exception $ e ) {
208
214
$ this ->inlineTranslation ->resume ();
209
215
$ this ->messageManager ->addError ($ e ->getMessage ());
@@ -212,7 +218,8 @@ public function execute()
212
218
)->setSharingForm (
213
219
$ this ->getRequest ()->getPostValue ()
214
220
);
215
- $ this ->_redirect ('*/*/share ' );
221
+ $ resultRedirect ->setPath ('*/*/share ' );
222
+ return $ resultRedirect ;
216
223
}
217
224
}
218
225
@@ -222,27 +229,28 @@ public function execute()
222
229
* Add 'wishlist_email_rss' layout handle.
223
230
* Add 'wishlist_email_items' layout handle.
224
231
*
232
+ * @param \Magento\Framework\View\Result\Layout $resultLayout
225
233
* @return void
226
234
*/
227
- protected function addLayoutHandles ()
235
+ protected function addLayoutHandles (ResultLayout $ resultLayout )
228
236
{
229
237
if ($ this ->getRequest ()->getParam ('rss_url ' )) {
230
- $ this -> _view -> getLayout ()-> getUpdate () ->addHandle ('wishlist_email_rss ' );
238
+ $ resultLayout ->addHandle ('wishlist_email_rss ' );
231
239
}
232
- $ this ->_view ->getLayout ()->getUpdate ()->addHandle ('wishlist_email_items ' );
233
- $ this ->_view ->loadLayoutUpdates ();
240
+ $ resultLayout ->addHandle ('wishlist_email_items ' );
234
241
}
235
242
236
243
/**
237
244
* Retrieve RSS link content (html)
238
245
*
239
246
* @param int $wishlistId
247
+ * @param \Magento\Framework\View\Result\Layout $resultLayout
240
248
* @return mixed
241
249
*/
242
- protected function getRssLink ($ wishlistId )
250
+ protected function getRssLink ($ wishlistId, ResultLayout $ resultLayout )
243
251
{
244
252
if ($ this ->getRequest ()->getParam ('rss_url ' )) {
245
- return $ this -> _view ->getLayout ()
253
+ return $ resultLayout ->getLayout ()
246
254
->getBlock ('wishlist.email.rss ' )
247
255
->setWishlistId ($ wishlistId )
248
256
->toHtml ();
@@ -252,11 +260,12 @@ protected function getRssLink($wishlistId)
252
260
/**
253
261
* Retrieve wishlist items content (html)
254
262
*
263
+ * @param \Magento\Framework\View\Result\Layout $resultLayout
255
264
* @return string
256
265
*/
257
- protected function getWishlistItems ()
266
+ protected function getWishlistItems (ResultLayout $ resultLayout )
258
267
{
259
- return $ this -> _view ->getLayout ()
268
+ return $ resultLayout ->getLayout ()
260
269
->getBlock ('wishlist.email.items ' )
261
270
->toHtml ();
262
271
}
0 commit comments