Is there any way to override old images with the new one, if the images names are the same?
The image in the assets folder is Image_1234678.jpg
the new image in the folder has the same name Image_1234678.jpg.
How were you uploading images before?
We did it via File manager in the assets pane. Then the images were assigned to the products. Now there are a folder with updated images on the disk , that have the same name as uploaded and linked. Is there any possibility to replace the assigned with the new aotimatically?
If you know the ContentLink or the ContentGuid of the new Images, then you can simply do this:
- Iterate over the products.
- Foreach the product, iterate over its CommerceMediaCollection, for each CommerceMedia you will have the ContentLink of the asset - get the content to get its name and match it with the maps you have.
- Replace the old CommerceMedia with new CommerceMedia points to new ContentLink.
- Save the product content.
If you don't know the ContentLink of new images then it'll be trickier. From the old CommerceMedia you can get the name, then search for the name to find new ContentLink. Of course it'll be slower.