|
How I did it
1) Database table eav_attributes
Search for the rows with attribute_code ‘image’, ‘small_image’ and ‘thumbnail’. Change the frontend_input field from ‘media_image’ to ‘text’.
2) app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php
Remove or comment out the following code (around line 570) which will allow image values to be imported:
if (in_array($field, $this->_imageFields)) { continue; }
Remove or comment out the following code (around line 640) which will prevent image importing:
$imageData = array(); foreach ($this->_imageFields as $field) { if (!empty($importData[$field]) && $importData[$field] != 'no_selection') { if (!isset($imageData[$importData[$field]])) { $imageData[$importData[$field]] = array(); } $imageData[$importData[$field]][] = $field; } }
foreach ($imageData as $file => $fields) { try { $product->addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'import' . $file, $fields); } catch (Exception $e) {} }
Finally, add this code above $product->setData($field, $setValue); (around line 620) which will set the image values to “no_selection” if empty:
if (in_array($field, $this->_imageFields) && empty($setValue)) { $setValue = "no_selection"; }
Now, in my csv import file under ‘image’,’small_image’ and ‘thumbnail’, I can just add ‘images/151118.jpg’ and that value will be added to the corresponding product as seen in the attachment above.
3) lib/Varien/File/Uploader.php
The following may not be necessary since I now can manually enter image names, but I disabled the file renaming and path dispersion functionality anyway.
disable file renaming:
static public function getNewFileName($destFile) { $fileInfo = pathinfo($destFile); /* Return filename before it's renamed */ return $fileInfo['basename']; if( file_exists($destFile) ) { $index = 1; $baseName = $fileInfo['filename'] . '.' . $fileInfo['extension']; while( file_exists($fileInfo['dirname'] . DIRECTORY_SEPARATOR . $baseName) ) { $baseName = $fileInfo['filename']. '_' . $index . '.' . $fileInfo['extension']; $index ++; } $destFileName = $baseName; } else { return $fileInfo['basename']; }
return $destFileName; }
disable path dispersion:
static public function getDispretionPath($fileName) { $char = 0; $dispretionPath = ''; /* Return empty path */ return $dispretionPath; while( ($char < 2) && ($char < strlen($fileName)) ) { if (empty($dispretionPath)) { $dispretionPath = DIRECTORY_SEPARATOR.('.' == $fileName[$char] ? '_' : $fileName[$char]); } else { $dispretionPath = self::_addDirSeparator($dispretionPath) . ('.' == $fileName[$char] ? '_' : $fileName[$char]); } $char ++; } return $dispretionPath; }
Even though I had to edit some database fields directly and edit some core code, the changes are pretty simple. Like I said before, separating image uploading from product uploading and not having to deal with image renaming is going to make my life much easier.
|