当您将产品图像上传到与现有图像同名的Magento时,Magento的正常行为是在新文件名的末尾添加“_1”。因此,如果我有一个名为“myFile.png”的图像并将第二个图像上传到具有相同名称的同一产品,Magento会将其重命名为“myFile_1.png”。我想消除这种重命名,并使用相同名称的文件替换现有文件。
我想我找到了相关的控制器:app / code / core / Mage / Adminhtml / controllers / Catalog / Product / GalleryController.php:
public function uploadAction()
{
try {
$uploader = new Mage_Core_Model_File_Uploader('image');
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->addValidateCallback('catalog_product_image',
Mage::helper('catalog/image'), 'validateUploadFile');
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$result = $uploader->save(
Mage::getSingleton('catalog/product_media_config')->getBaseTmpMediaPath()
);
Mage::dispatchEvent('catalog_product_gallery_upload_image_after', array(
'result' => $result,
'action' => $this
));
/**
* Workaround for prototype 1.7 methods "isJSON", "evalJSON" on Windows OS
*/
$result['tmp_name'] = str_replace(DS, "/", $result['tmp_name']);
$result['path'] = str_replace(DS, "/", $result['path']);
$result['url'] = Mage::getSingleton('catalog/product_media_config')->getTmpMediaUrl($result['file']);
$result['file'] = $result['file'] . '.tmp';
$result['cookie'] = array(
'name' => session_name(),
'value' => $this->_getSession()->getSessionId(),
'lifetime' => $this->_getSession()->getCookieLifetime(),
'path' => $this->_getSession()->getCookiePath(),
'domain' => $this->_getSession()->getCookieDomain()
);
} catch (Exception $e) {
$result = array(
'error' => $e->getMessage(),
'errorcode' => $e->getCode());
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
我已经尝试将setAllowedRenameFiles()设置为false。我也尝试过评论它。但这些似乎都没有产生预期的结果。
有关如何启用Magento覆盖同名现有文件的任何想法?