Does anyone have any tips for writing a script that would delete all duplicate images for a product's variations? The way our products were migrated in resulted in each simple product having its own image (same paths), so they all show up in the configurable product's gallery.
Since I'm dealing with a ton of products, I'm looking for a effective way to programmatically find and delete these products.
So far I've tried this:
- Creating/loading a product collection factory
- For each product, check if it's a configurable, and then get its variations with getUsedProducts().
- Get Media Gallery Entries, then iterate through and put each url into an array
- For each child, get gallery entries and for each of those unset them if they're in the array
- Set media gallery entries for the child using the new array, and save using the product repository.
I haven't been able to get this to work, so you can probably ignore the above if it's nonsensical. It's likely that I've botched scope stuff with so many iterations going on, but I'm hoping someone can tell me if I'm on the right track or not.