justine123 Posted July 27, 2022 Share Posted July 27, 2022 Hi, So I uploaded wrong images for many products (product ID range of 6154 - 6983) and I wanted to delete the additional images for these products. The cover image for each of these products are correct, it's just that I imported another batch of images but they were wrong. I tried to manually delete them but there are around 800 products. Is there a way to delete them in the database? Link to comment Share on other sites More sharing options...
Ali Samie Posted July 27, 2022 Share Posted July 27, 2022 search for Image.php class and find out how it deletes images with id_product. Then create a dummy mdoule, add a front controller and run the script with id_product range Link to comment Share on other sites More sharing options...
lordignus Posted July 27, 2022 Share Posted July 27, 2022 Something like this should do the trick... $product_id_min = 6154; $product_id_max = 6983; $id_lang_default = Configuration::get('PS_LANG_DEFAULT'); for($i = $product_id_min; $i <= $product_id_max; $i++) { $product = new Product($i); $images = $product->getImages($id_lang_default); foreach($images as $image){ if($image['cover'] == 1){ continue; } $obj_image = new Image($image['id_image']); $obj_image->delete(); } } Link to comment Share on other sites More sharing options...
Ali Samie Posted July 27, 2022 Share Posted July 27, 2022 you can also try using the entityManager https://devdocs.prestashop.com/1.7/modules/concepts/doctrine/ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now