How to Change Magento Directory Structure for Images When Importing

importmagento-1.9magmiproduct-images

What I'm trying to do is change the default folder structure of imported images.
For example when you import an image magento defaults the directory structure to the first and second letter of the image to create the directory structure under /media/catalog/product/X/Y/XYimage.jpg

I want to be able to modify the core to allow me to change it to something like:
/media/catalog/product/SKU/XYZ/SKUXYZimage.jpg
hence the first 3 letters are the top level of the directory and the next 3 letters are the second level of the directory.

Best Answer

Backtracing the code

  1. Mage_Catalog_Model_Product::addImageToMediaGallery
  2. Mage_Catalog_Model_Product_Attribute_Backend_Media::addImage
  3. Varien_File_Uploader::getDispretionPath

It seems that the path is build here. Since you can't override a Varien file from a custom module you will have to copy the file to app/code/local/Varien/File/Uploader.php. There you can change the way the path is build.

However, this will not only affect products in that case. You might want to override Mage_Catalog_Model_Product_Attribute_Backend_Media::addImage from a custom module to limit the scope of the changes to just products. So instead of calling Mage_Core_Model_File_Uploader::getDispretionPath on line 286 you might want to change that line into calling a custom method for returning the path.

Related Topic