@@ -32,19 +32,37 @@ class ImageProvider
32
32
*/
33
33
protected $ customerDataItem ;
34
34
35
+ /**
36
+ * @var \Magento\Catalog\Helper\Image
37
+ */
38
+ private $ imageHelper ;
39
+
40
+ /**
41
+ * @var \Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface
42
+ */
43
+ private $ itemResolver ;
44
+
35
45
/**
36
46
* @param \Magento\Quote\Api\CartItemRepositoryInterface $itemRepository
37
47
* @param \Magento\Checkout\CustomerData\ItemPoolInterface $itemPool
38
48
* @param DefaultItem|null $customerDataItem
49
+ * @param \Magento\Catalog\Helper\Image $imageHelper
50
+ * @param \Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface $itemResolver
39
51
*/
40
52
public function __construct (
41
53
\Magento \Quote \Api \CartItemRepositoryInterface $ itemRepository ,
42
54
\Magento \Checkout \CustomerData \ItemPoolInterface $ itemPool ,
43
- \Magento \Checkout \CustomerData \DefaultItem $ customerDataItem = null
55
+ \Magento \Checkout \CustomerData \DefaultItem $ customerDataItem = null ,
56
+ \Magento \Catalog \Helper \Image $ imageHelper = null ,
57
+ \Magento \Catalog \Model \Product \Configuration \Item \ItemResolverInterface $ itemResolver = null
44
58
) {
45
59
$ this ->itemRepository = $ itemRepository ;
46
60
$ this ->itemPool = $ itemPool ;
47
61
$ this ->customerDataItem = $ customerDataItem ?: ObjectManager::getInstance ()->get (DefaultItem::class);
62
+ $ this ->imageHelper = $ imageHelper ?: ObjectManager::getInstance ()->get (\Magento \Catalog \Helper \Image::class);
63
+ $ this ->itemResolver = $ itemResolver ?: ObjectManager::getInstance ()->get (
64
+ \Magento \Catalog \Model \Product \Configuration \Item \ItemResolverInterface::class
65
+ );
48
66
}
49
67
50
68
/**
@@ -58,9 +76,30 @@ public function getImages($cartId)
58
76
$ items = $ this ->itemRepository ->getList ($ cartId );
59
77
/** @var \Magento\Quote\Model\Quote\Item $cartItem */
60
78
foreach ($ items as $ cartItem ) {
61
- $ allData = $ this ->customerDataItem ->getItemData ($ cartItem );
62
- $ itemData [$ cartItem ->getItemId ()] = $ allData ['product_image ' ];
79
+ $ itemData [$ cartItem ->getItemId ()] = $ this ->getProductImageData ($ cartItem );
63
80
}
64
81
return $ itemData ;
65
82
}
83
+
84
+ /**
85
+ * Get product image data
86
+ *
87
+ * @param \Magento\Quote\Model\Quote\Item $cartItem
88
+ *
89
+ * @return array
90
+ */
91
+ private function getProductImageData ($ cartItem )
92
+ {
93
+ $ imageHelper = $ this ->imageHelper ->init (
94
+ $ this ->itemResolver ->getFinalProduct ($ cartItem ),
95
+ 'mini_cart_product_thumbnail '
96
+ );
97
+ $ imageData = [
98
+ 'src ' => $ imageHelper ->getUrl (),
99
+ 'alt ' => $ imageHelper ->getLabel (),
100
+ 'width ' => $ imageHelper ->getWidth (),
101
+ 'height ' => $ imageHelper ->getHeight (),
102
+ ];
103
+ return $ imageData ;
104
+ }
66
105
}
0 commit comments