Reputation: 75
In my site, the product image are duplicated many times? how to remove the repeat data in the database.
Eg: The correct product image is: product.jpg producta.jpg productb.jpg
now, there are
product.jpg producta.jpg productb.jpg product.jpg producta.jpg productb.jpg
. How to make them unique? thank you.
Upvotes: 0
Views: 459
Reputation: 4141
Just delete them? What is the exact problem? You have products with a lot of product images attached.
You can load the product, loop over the mediaGallery images, save the names in an array, remove all images when the name already exists and save the image. Something like this:
// get the media-gallery backend model to remove images
$attributes = $this->getTypeInstance(true)->getSetAttributes($this);
if (!isset($attributes['media_gallery'])) {
return $this;
}
$mediaGalleryAttribute = $attributes['media_gallery'];
/* @var $mediaGalleryAttribute Mage_Catalog_Model_Resource_Eav_Attribute */
$mediaGalleryAttribute->getBackend()->addImage($this, $file, $mediaAttribute, $move, $exclude);
Mage_Catalog_Model_Product_Attribute_Backend_Media::removeImage(Mage_Catalog_Model_Product $product, $file)
Upvotes: 1