imageBuilder = $imageBuilder; $this->storeManager = $storeManager; $this->appEmulation = $appEmulation; } /** * @param Product $product * @param string $imageId * @param array $attributes * @return Image * @throws \Exception */ public function getImage(Product $product, $imageId, $attributes = []) { $storeId = $this->storeManager->getStore()->getId(); $this->appEmulation->startEnvironmentEmulation($storeId, Area::AREA_FRONTEND, true); try { $image = $this->imageBuilder->create($product, $imageId, $attributes); } catch (\Exception $exception) { $this->appEmulation->stopEnvironmentEmulation(); throw $exception; } $this->appEmulation->stopEnvironmentEmulation(); return $image; } }