7
7
8
8
use Magento \Catalog \Model \Product \Image \NotLoadInfoImageException ;
9
9
use Magento \Customer \CustomerData \SectionSourceInterface ;
10
+ use Magento \Framework \App \ObjectManager ;
11
+ use Magento \Wishlist \Block \Customer \Wishlist \Item \Column \Image ;
10
12
11
13
/**
12
14
* Wishlist section
@@ -38,22 +40,30 @@ class Wishlist implements SectionSourceInterface
38
40
*/
39
41
protected $ block ;
40
42
43
+ /**
44
+ * @var \Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Image
45
+ */
46
+ private $ image ;
47
+
41
48
/**
42
49
* @param \Magento\Wishlist\Helper\Data $wishlistHelper
43
50
* @param \Magento\Wishlist\Block\Customer\Sidebar $block
44
51
* @param \Magento\Catalog\Helper\ImageFactory $imageHelperFactory
45
52
* @param \Magento\Framework\App\ViewInterface $view
53
+ * @param Image|null $image
46
54
*/
47
55
public function __construct (
48
56
\Magento \Wishlist \Helper \Data $ wishlistHelper ,
49
57
\Magento \Wishlist \Block \Customer \Sidebar $ block ,
50
58
\Magento \Catalog \Helper \ImageFactory $ imageHelperFactory ,
51
- \Magento \Framework \App \ViewInterface $ view
59
+ \Magento \Framework \App \ViewInterface $ view ,
60
+ Image $ image = null
52
61
) {
53
62
$ this ->wishlistHelper = $ wishlistHelper ;
54
63
$ this ->imageHelperFactory = $ imageHelperFactory ;
55
64
$ this ->block = $ block ;
56
65
$ this ->view = $ view ;
66
+ $ this ->image = $ image ?? ObjectManager::getInstance ()->get (Image::class);
57
67
}
58
68
59
69
/**
@@ -122,7 +132,7 @@ protected function getItemData(\Magento\Wishlist\Model\Item $wishlistItem)
122
132
{
123
133
$ product = $ wishlistItem ->getProduct ();
124
134
return [
125
- 'image ' => $ this ->getImageData ($ product ),
135
+ 'image ' => $ this ->getImageData ($ this -> image -> getProductForThumbnail ( $ wishlistItem ) ),
126
136
'product_sku ' => $ product ->getSku (),
127
137
'product_id ' => $ product ->getId (),
128
138
'product_url ' => $ this ->wishlistHelper ->getProductUrl ($ wishlistItem ),
@@ -149,14 +159,6 @@ protected function getItemData(\Magento\Wishlist\Model\Item $wishlistItem)
149
159
*/
150
160
protected function getImageData ($ product )
151
161
{
152
- /*Set variant product if it is configurable product.
153
- It will show variant product image in sidebar instead of configurable product image.*/
154
- $ simpleOption = $ product ->getCustomOption ('simple_product ' );
155
- if ($ simpleOption !== null ) {
156
- $ optionProduct = $ simpleOption ->getProduct ();
157
- $ product = $ optionProduct ;
158
- }
159
-
160
162
/** @var \Magento\Catalog\Helper\Image $helper */
161
163
$ helper = $ this ->imageHelperFactory ->create ()
162
164
->init ($ product , 'wishlist_sidebar_block ' );
0 commit comments