Today we will explain how you can find products with empty images. By empty images we imply those pictures, which are indexed in the database, but the files are not physically located on the server. In such case users will see a gray question mark instead of a placeholder with the caption that the image for that product is not available.
Partner With Us
Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/*prepare list of broken images*/ require(dirname(__FILE__).'/config/config.inc.php'); // you might need to change the path to the file 'config.inc.php' if you are not in the root folder $id_lang = 1; //getting links for one language. This is enough to identify empty images $i = 0; $limit = 100; $filename = 'broken_urls.txt'; file_put_contents($filename, '', LOCK_EX); //remove old content //file_put_contents($filename, '', FILE_APPEND | LOCK_EX); //append content do { $images = Db::getInstance()->executeS(' select * from `'._DB_PREFIX_.'image` i limit ' . (int)($i++ * $limit) . ', ' . (int)$limit . ' '); //receiving the stack of images foreach ($images as $image) { $imgObj = new Image($image['id_image'], $id_lang); $image_path = _PS_PROD_IMG_DIR_ . $imgObj->getImgPath() . '.' . $imgObj->image_format; if (!file_exists($image_path)) { //verifying, whether the file with the image exists $productObj = new Product($image['id_product'], NULL, $id_lang); //creating a product object for link generation print_r($image['id_product'] . ' => ' . Context::getContext()->link->getImageLink($productObj->link_rewrite, $image['id_image']) . chr(10)); //die; file_put_contents($filename, $image['id_product'] . ' => ' . Context::getContext()->link->getImageLink($productObj->link_rewrite, $image['id_image']) . chr(10), FILE_APPEND | LOCK_EX); } } } while(count($images)); |
As a result we will have a file with the list of products on the screen. For such products you need to delete the entries in the table ‘ps_imаge’, ‘ps_imаge_lаng’ and ‘ps_imаge_shоp’, and upload images for these products again.
Partner With Us
Looking for a partner to grow your business? We are the right company to bring your webstore to success.
Talk to Igor
Hi Roberto,
that sounds really strange.
Please, contact our support team at [email protected] and we will try to help you.
Hi, this script looks really helpful as with the Prestashop CSV import function issues with image import I found myself with thousands of products with images missing.
I cannot make this work though, I have php installed, the file is correctly loaded through ftp and I can run the script in command line (I have Prestashop 1.6 on Ubuntu, on AWS, I access to cmd using Putty), no error comes up, but it doesn’t do anything, there’s no output txt file anywhere to be found.
Care to give me a hint?
Great script! Exactly what I was looking for.. Thanks a lot!
Hi Alex. Thank you very much for the script. I just don’t know how to implement it? Do i create a file using notepad and uploading to the root foler of the server, then access the files through my browser? Thank you.
raf,
Please contact our support team at [email protected] to get get a quote.
Hello,
maybe you can help me with this. I sell engraved products and i use the Customization feature found on Product. Is there a way to enter fields and labels of the customization in bulk via csv file?
Where are these data stored?
Thank you.
Bob,
What do you mean by broken urls? Can you show an example?
Al,
Not at the moment. But it is a good topic for the next article)
Costas,
Thank you!
please hello how to implement the code you provided to check the broken urls pleas!!!
Do you have a version that does this task on Magento CE 1.9?
Goood job! !
Hi Javier,
Let me assure you that this code is good for version 1.6. Please, enable displaying errors to find out what exactly is wrong. But most probably you have specified a wrong path to the file config/config.inc.php
I do not work, the screen stays blank.
It is worth for prestashop 1.6 ??