I am doing a product import routine and have images added to my product. The problem I have is that magento creates a dispretion path and then add's some numbers onto the end of my image file name to ensure it's not a duplicate. I need to find a way to check if
myimage.jpg has been added to a product or not.
I can find the dispretion path using
Mage_Core_Model_File_Uploader::getDispretionPath($fileName); so that isn't a problem but from what I can see there isn't a way to map the file name I uploaded to the one magento renamed it do, for instance:
I add an image called
BadgersSmall.jpg and this is what magento returns as part of the MediaGallery collection
[value_id] => 5 [file] => /B/a/BadgersSmall_6_1.jpg [label] => [position] => 2 [disabled] => 0 [label_default] => [position_default] => 2 [disabled_default] => 0 [url] => http://www.localhost.com:8080/magento/media/catalog/product/B/a/BadgersSmall_6_1.jpg [id] => 5 [path] => C:\xampp\htdocs\magento\media\catalog\product\B\a\BadgersSmall_6_1.jpg
The only thing I can think of at this point is running
_getNotDuplicatedFilename($fileName, $dispretionPath); on my current image and then checking the index at the end of the file, subtract 1 and that "should" be the previous file I uploaded but this solution is simply horrible.
EDIT My new plan is to create a database table that will hold my product code, file name and the file name magento creates. I will insert this when I add new images. I will also need to add something in to observe the delete image event so I can remove the entry as well.