@@ -46,23 +46,38 @@ abstract class AbstractEmail extends \Magento\Framework\View\Element\Template
46
46
*/
47
47
protected $ imageBuilder ;
48
48
49
+ /**
50
+ * @var \Magento\Store\Model\App\Emulation
51
+ */
52
+ private $ appEmulation ;
53
+
54
+ /**
55
+ * @var \Magento\Store\Model\StoreManagerInterface
56
+ */
57
+ private $ storeManager ;
58
+
49
59
/**
50
60
* @param \Magento\Framework\View\Element\Template\Context $context
51
- * @param \Magento\Framework\Filter\Input\MaliciousCode $maliciousCode
52
- * @param PriceCurrencyInterface $priceCurrency
53
- * @param \Magento\Catalog\Block\Product\ImageBuilder $imageBuilder
54
- * @param array $data
61
+ * @param \Magento\Framework\Filter\Input\MaliciousCode $maliciousCode
62
+ * @param PriceCurrencyInterface $priceCurrency
63
+ * @param \Magento\Catalog\Block\Product\ImageBuilder $imageBuilder
64
+ * @param \Magento\Store\Model\App\Emulation $appEmulation
65
+ * @param array $data
55
66
*/
56
67
public function __construct (
57
68
\Magento \Framework \View \Element \Template \Context $ context ,
58
69
\Magento \Framework \Filter \Input \MaliciousCode $ maliciousCode ,
59
70
PriceCurrencyInterface $ priceCurrency ,
60
71
\Magento \Catalog \Block \Product \ImageBuilder $ imageBuilder ,
72
+ \Magento \Store \Model \App \Emulation $ appEmulation ,
61
73
array $ data = []
62
74
) {
63
75
$ this ->imageBuilder = $ imageBuilder ;
64
76
$ this ->priceCurrency = $ priceCurrency ;
65
77
$ this ->_maliciousCode = $ maliciousCode ;
78
+ $ this ->appEmulation = $ appEmulation ;
79
+ $ this ->storeManager = $ context ->getStoreManager ();
80
+
66
81
parent ::__construct ($ context , $ data );
67
82
}
68
83
@@ -212,18 +227,29 @@ public function getProductPriceHtml(
212
227
}
213
228
214
229
/**
215
- * Retrieve product image
230
+ * Retrieve product image.
216
231
*
217
- * @param \Magento\Catalog\Model\Product $product
218
- * @param string $imageId
232
+ * @param $product
233
+ * @param $imageId
219
234
* @param array $attributes
235
+ *
220
236
* @return \Magento\Catalog\Block\Product\Image
221
237
*/
222
238
public function getImage ($ product , $ imageId , $ attributes = [])
223
239
{
224
- return $ this ->imageBuilder ->setProduct ($ product )
240
+ $ this ->appEmulation ->startEnvironmentEmulation (
241
+ $ this ->storeManager ->getStore ()->getId (),
242
+ \Magento \Framework \App \Area::AREA_FRONTEND ,
243
+ true
244
+ );
245
+
246
+ $ image = $ this ->imageBuilder ->setProduct ($ product )
225
247
->setImageId ($ imageId )
226
248
->setAttributes ($ attributes )
227
249
->create ();
250
+
251
+ $ this ->appEmulation ->stopEnvironmentEmulation ();
252
+
253
+ return $ image ;
228
254
}
229
255
}
0 commit comments