From b91940e375734ebba64ccb953c87128584a95a18 Mon Sep 17 00:00:00 2001 From: Ankur Raiyani Date: Fri, 18 Dec 2020 16:58:55 +0530 Subject: [PATCH] Handled 'no_selection' image when there are no image in product to show placeholder image from magento --- Plugin/Catalog/Block/Product/ImageFactory.php | 4 ++++ Plugin/Catalog/Model/Product/Image/UrlBuilder.php | 4 ++++ Plugin/ImageHelper.php | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/Plugin/Catalog/Block/Product/ImageFactory.php b/Plugin/Catalog/Block/Product/ImageFactory.php index 866d70a6..00d2464f 100644 --- a/Plugin/Catalog/Block/Product/ImageFactory.php +++ b/Plugin/Catalog/Block/Product/ImageFactory.php @@ -138,6 +138,10 @@ public function aroundCreate(CatalogImageFactory $catalogImageFactory, callable return $imageBlock; } + if ($imageBlock->getImageUrl() === 'no_selection') { + return $imageBlock; + } + if ($this->configuration->isEnabledLazyload()) { $useOldImageTheme = is_string($imageBlock->getCustomAttributes()) ? 'old_' : ''; $imageBlock->setTemplate( diff --git a/Plugin/Catalog/Model/Product/Image/UrlBuilder.php b/Plugin/Catalog/Model/Product/Image/UrlBuilder.php index b20f439c..1f921a15 100644 --- a/Plugin/Catalog/Model/Product/Image/UrlBuilder.php +++ b/Plugin/Catalog/Model/Product/Image/UrlBuilder.php @@ -117,6 +117,10 @@ public function aroundGetUrl(CatalogUrlBuilder $catalogUrlBuilder, callable $pro return $url; } + if ($url === 'no_selection') { + return $url; + } + if (class_exists('\Magento\Catalog\Model\Product\Image\ParamsBuilder')) { $this->imageParamsBuilder = $this->objectManager->get('\Magento\Catalog\Model\Product\Image\ParamsBuilder'); } else { diff --git a/Plugin/ImageHelper.php b/Plugin/ImageHelper.php index 65ab9787..e28fd14b 100644 --- a/Plugin/ImageHelper.php +++ b/Plugin/ImageHelper.php @@ -138,6 +138,10 @@ public function aroundGetUrl(CatalogImageHelper $helper, \Closure $originalMetho return $originalMethod(); } + if ($imageBlock->getImageUrl() === 'no_selection') { + return $imageBlock; + } + $imagePath = $this->imageFile ?: $this->product->getData($helper->getType()); $image = $this->imageFactory->build(sprintf('catalog/product%s', $imagePath), $originalMethod);