5
5
*/
6
6
namespace Magento \Wishlist \Controller \Index ;
7
7
8
+ use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory as ProductCollectionFactory ;
8
9
use Magento \Framework \App \Action ;
9
10
use Magento \Framework \Data \Form \FormKey \Validator ;
10
11
use Magento \Framework \Exception \NotFoundException ;
@@ -27,18 +28,27 @@ class Remove extends \Magento\Wishlist\Controller\AbstractIndex
27
28
*/
28
29
protected $ formKeyValidator ;
29
30
31
+ /**
32
+ * @var ProductCollectionFactory
33
+ */
34
+ private $ productCollectionFactory ;
35
+
30
36
/**
31
37
* @param Action\Context $context
32
38
* @param WishlistProviderInterface $wishlistProvider
33
39
* @param Validator $formKeyValidator
40
+ * @param ProductCollectionFactory|null $productCollectionFactory
34
41
*/
35
42
public function __construct (
36
43
Action \Context $ context ,
37
44
WishlistProviderInterface $ wishlistProvider ,
38
- Validator $ formKeyValidator
45
+ Validator $ formKeyValidator ,
46
+ ProductCollectionFactory $ productCollectionFactory = null
39
47
) {
40
48
$ this ->wishlistProvider = $ wishlistProvider ;
41
49
$ this ->formKeyValidator = $ formKeyValidator ;
50
+ $ this ->productCollectionFactory = $ productCollectionFactory
51
+ ?: \Magento \Framework \App \ObjectManager::getInstance ()->get (ProductCollectionFactory::class);
42
52
parent ::__construct ($ context );
43
53
}
44
54
@@ -69,10 +79,15 @@ public function execute()
69
79
try {
70
80
$ item ->delete ();
71
81
$ wishlist ->save ();
82
+ $ product = $ this ->productCollectionFactory
83
+ ->create ()
84
+ ->addIdFilter ($ item ->getProductId ())
85
+ ->addAttributeToSelect ('name ' )
86
+ ->getFirstItem ();
72
87
$ this ->messageManager ->addComplexSuccessMessage (
73
88
'removeWishlistItemSuccessMessage ' ,
74
89
[
75
- 'product_name ' => $ item -> getProduct () ->getName ()
90
+ 'product_name ' => $ product ->getName ()
76
91
]
77
92
);
78
93
} catch (\Magento \Framework \Exception \LocalizedException $ e ) {
0 commit comments