Question

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.

Was it helpful?

Solution 2

This is a simple workaround and just tested over 60k products. install Magmi (Search Google).Navigate to \magmi\plugins\extra\itemprocessors\imageprocessor open imageitattributeemprocessor.php with your favorite editor go to and replace 496 to 505 with this small modification.

$i1 = $bimgfile[0];
    $i2 = $bimgfile[1];
    $i3 = $bimgfile[2];
    $i4 = $bimgfile[3];
    $i5 = $bimgfile[4];
    $i6 = $bimgfile[5];
    // magento image value (relative to media catalog)
    $impath = "/$i1$i2$i3/$i4$i5$i6/$bimgfile";
    // target directory;
    $l2d = "media/catalog/product/$i1$i2$i3/$i4$i5$i6";

As you can see I chose on $impath to set my structure up as "/$i1$i2$i3/$i4$i5$i6/$bimgfile" Translated sku123456.jpg would be media/catalog/product/sku/123/sku123456.jpg Sorry for the crude drawing (I'm New at this) Always remember if you upgrade Magmi this can be over written so always back up your files.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top