Change product image placeholder based on product – Magento 2

We need to override the below two functions in vendor/magento/module-catalog/Helper/Image.php

Below function change the placeholder image in the home page, category page, product page.

public function getPlaceholder($placeholder = null)
{
	$product = $this->getProduct();
	if($product->getName() == "Test Name") // here your condition
	{
		// logic to retrieve new url
		return $new_palceholder_url;
	}
        ...............//remining magento core codes
}

Below function change the placeholder image in cart page.

public function getUrl()
{
	$product = $this->getProduct();
	if($product->getName() == "Test Name") // here your condition
	{
		// logic to retrieve new url
		return $new_palceholder_url;
	}
        ...............//remining magento core codes
}

I hope it helps. Thanks.

#customization #magento2 #placeholderimage

0 views0 comments

Recent Posts

See All

Magento 2 CMS block with the same ID already exists

I have seen the below error when I open cms block grid something went wrong with processing the default view and we have restored the filter to its original state. I found the below log in the excepti

How to generate bearer token - Magento 2 REST API

We can generate the admin bearer token using the below command. Please run the below command in the terminal to generate a token. curl -XPOST -H 'Content-Type: application/json' http://www.domain.com/

Magento 2 script tag and available options in layout xml

We can add a script via layout XML file in Magento 2. The below format will stop the HTML parse until js downloaded and executed. <script src="Bilal_Usean/js/sample.min.js" /> The below format will st