Magento: Can’t see product images in category page
Set product image as small image and thumbnail programatically
If you see your images in product detail page but don’t see it in category page, it’s because your product have images (image attribute filled) but not small_image and thumbnail which are required to display on category page. If there are only few products you want to set small_image and thumbnail, then it’s easy to go to Manage Products > Individual Product > Images tab > Set small image and thumbnail radio button. But when it comes to hundreds/thousands of products, you better want it programatically way.
Make a file in your Magento root and place the below code in it. Then run that file and you have just copied your Product Image to small image and thumbnail as well!
<?php | |
ini_set('display_errors',1); | |
require 'app/Mage.php'; | |
Mage::app(); | |
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*'); | |
foreach ($products as $product) { | |
if (!$product->hasImage()) continue; | |
if (!$product->hasSmallImage()) $product->setSmallImage($product->getImage()); | |
if (!$product->hasThumbnail()) $product->setThumbnail($product->getImage()); | |
$product->save(); | |
} | |
echo 'Finished!'; | |
?> |
4 Comments
Leave a comment
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)
Tag Cloud
500 internal server error admin answers attribute bug category checkbox checkout cookie customer difference domain name EAV error event extension interview invoice jquery linux magento magento2 magento admin magento error magento interview questions magento orm mysql observer order pinterest product products questions redirect register remove script session simplexml to array state status study guide tax url wordpress
Very nice Info….
This is helpful to develop maegnto store …
Hi Kalpesh, I just wanted to say I appreciate your blog. It is nice of you to document things you have discovered in Magento. I just read your post about states vs. statuses and found it to be helpful.
Very helpful post…..
Thanks Kalpesh
Please let me know the file name….