Jump to content

How do I delete additional images of products (not the cover image) without deleting it manually one by one?


justine123

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...