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