- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
product image in home page not showing images %5C showing in the code instead of \
product image in home page not showing images "%5C" showing in the code instead of "\"
sample product image code:
<img class="product-image-photo" src="http//domain.com/media/catalog/product%5Cproduct%5C//3/7/37606.png" loading="lazy">
The product pages are showing the images. It's just the home page or other pages adding in "blocks" having this issue.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: product image in home page not showing images %5C showing in the code instead of \
Hi @isabelchuabf02 ,
Please check below ways.
1) You can resolve issue by just replacing %5C with /
str_replace("%5C","/",$imageUrl);
2) You can get product images proper path by using below way:
protected $_productRepositoryFactory; public function __construct( \Magento\Catalog\Api\ProductRepositoryInterfaceFactory $productRepositoryFactory ) { $this->_productRepositoryFactory = $productRepositoryFactory; }
$product = $this->_productRepositoryFactory->create() ->getById($item->getProductId()); $product->getData('image'); $product->getData('thumbnail'); $product->getData('small_image');
Hope it helps!
Thanks
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: product image in home page not showing images %5C showing in the code instead of \
Hello @isabelchuabf02
Can you please refer below code to get images of product by id:
$objectmanager = \Magento\Framework\App\ObjectManager::getInstance(); $product_id = 32; //Replace with your product ID $productimages = array(); $product = $objectmanager ->create('Magento\Catalog\Model\Product')->load($product_id); $productimages = $product->getMediaGalleryImages(); foreach($productimages as $productimage) { echo "<img src=".$productimage['url']. " width="100" height="100" />"; }
It may help you!
Thank you
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: product image in home page not showing images %5C showing in the code instead of \
I am using magento 2.4.4, where can I find the file to change %5C? I tried to ctrl+shift+f but it's not searchable. I also can't understand what I need to change from this?
protected $_productRepositoryFactory
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: product image in home page not showing images %5C showing in the code instead of \
Sorry I'm very new to Magento and I don't understand where I'll put this code. This is for every product image that is shown as "catalog product list"
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: product image in home page not showing images %5C showing in the code instead of \
Hi @isabelchuabf02 ,
Could you please confirm on which pages you are facing issue?
1) Home Page
2) Category Listing Page (PLP page)
3) Product View Page
4) Cart Page
If problem only available on specific page like home page than could you please share screenshot of that?
Hope it helps!
Thanks
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: product image in home page not showing images %5C showing in the code instead of \
it's all of the pages that would have the "catalog product list".
the code looks like this
They appear like this
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: product image in home page not showing images %5C showing in the code instead of \
Hi @isabelchuabf02 ,
Try below thing:
php bin/magento catalog:image:resize
Check again on front-end.
Hope it helps!
Thanks
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: product image in home page not showing images %5C showing in the code instead of \
I did this before and did it again but it's still not working
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: product image in home page not showing images %5C showing in the code instead of \
Hi @isabelchuabf02 ,
Are you using any lazyload extension for images?
Please check custom extensions that available in your project and if yes then for testing purpose please disable it and refresh cache and test again on front-end.
Without checking actual code and db I cant provide accurate solution but this may be the case.
Hope it helps!
Thanks