imageFactory = $imageFactory; } /** * Retrieve product image * * @param \Magento\Catalog\Model\Product $product * @param string $imageId * @return string */ public function getProductImage($product, $imageId = 'mpsearch_image') { $imageUrl = $this->imageFactory->create() ->init($product, $imageId) ->getUrl(); $baseMediaUrl = $this->getSearchMediaUrl(); if (strpos($imageUrl, $baseMediaUrl) === 0) { $imageUrl = substr($imageUrl, strlen($baseMediaUrl)); } return $imageUrl; } /** * @return string */ public function getSearchMediaUrl() { return $this->getBaseMediaUrl() . '/catalog/product/'; } /** * @param $fileName * @param $content */ public function createJsFile($fileName, $content) { try { $this->mediaDirectory->writeFile($fileName, $content); } catch (\Exception $e) { $this->_logger->critical($e->getMessage()); } } /** * @return $this */ public function removeJsPath() { $this->removePath(self::TEMPLATE_MEDIA_PATH); return $this; } }