Skip to content

Commit a9e2db7

Browse files
author
Jeroen
authored
Fix getImage method when sending product alert email
1 parent f215f3d commit a9e2db7

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

app/code/Magento/ProductAlert/Block/Email/AbstractEmail.php

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,38 @@ abstract class AbstractEmail extends \Magento\Framework\View\Element\Template
4646
*/
4747
protected $imageBuilder;
4848

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+
4959
/**
5060
* @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
5566
*/
5667
public function __construct(
5768
\Magento\Framework\View\Element\Template\Context $context,
5869
\Magento\Framework\Filter\Input\MaliciousCode $maliciousCode,
5970
PriceCurrencyInterface $priceCurrency,
6071
\Magento\Catalog\Block\Product\ImageBuilder $imageBuilder,
72+
\Magento\Store\Model\App\Emulation $appEmulation,
6173
array $data = []
6274
) {
6375
$this->imageBuilder = $imageBuilder;
6476
$this->priceCurrency = $priceCurrency;
6577
$this->_maliciousCode = $maliciousCode;
78+
$this->appEmulation = $appEmulation;
79+
$this->storeManager = $context->getStoreManager();
80+
6681
parent::__construct($context, $data);
6782
}
6883

@@ -212,18 +227,29 @@ public function getProductPriceHtml(
212227
}
213228

214229
/**
215-
* Retrieve product image
230+
* Retrieve product image.
216231
*
217-
* @param \Magento\Catalog\Model\Product $product
218-
* @param string $imageId
232+
* @param $product
233+
* @param $imageId
219234
* @param array $attributes
235+
*
220236
* @return \Magento\Catalog\Block\Product\Image
221237
*/
222238
public function getImage($product, $imageId, $attributes = [])
223239
{
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)
225247
->setImageId($imageId)
226248
->setAttributes($attributes)
227249
->create();
250+
251+
$this->appEmulation->stopEnvironmentEmulation();
252+
253+
return $image;
228254
}
229255
}

0 commit comments

Comments
 (0)