有人知道如何让Magento使用图像的实际基本URL而不是缓存的图像吗
使用Magento Community V 1.6.2.0
如果我看一个产品图片的URL,你会得到这样的东西…
/介质/目录/产品/缓存/1/image/390x/5e06319eda06f020e43594a9c230972d/1/1/11012001-J-1Front-Man/.jpg
我需要它更像:
/介质/目录/产品/11012001-J-1Front-Man/.jpg
原因是我正在使用M2EPro扩展,它允许您将在Magento销售/销售的产品与易趣/亚马逊同步问题是易趣不允许图片URL超过150个字符MD5散列和其他混合变量(我认为源于/app/code/core/Mage/Catalog/Helper/Image.php)使URL太长,无法用于我的许多图像。
当M2EPro运行时,它会提取缓存的图像(因为这是Magento指定的主图像)。我相信我只需要引用一个绝对的URL,还没能把这些放在一起。
我见过很多类似的问题,这些问题持续多年,但没有明确的答案。如果我先找到答案,我会在这里发布,但任何帮助都是非常非常感谢的
上面提到的Image.php文件中的当前代码:
$this->_baseFile = $baseFile;
// build new filename (most important params)
$path = array(
Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(),
Mage::app()->getStore()->getId(),
$path[] = $this->getDestinationSubdir()
);
if((!empty($this->_width)) || (!empty($this->_height)))
$path[] = "{$this->_width}x{$this->_height}";
// add misk params as a hash
$miscParams = array(
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_rgbToString($this->_backgroundColor),
'angle' . $this->_angle,
'quality' . $this->_quality
);
// if has watermark add watermark params to hash
if ($this->getWatermarkFile()) {
$miscParams[] = $this->getWatermarkFile();
$miscParams[] = $this->getWatermarkImageOpacity();
$miscParams[] = $this->getWatermarkPosition();
$miscParams[] = $this->getWatermarkWidth();
$miscParams[] = $this->getWatermarkHeigth();
}
$path[] = md5(implode('_', $miscParams));
// append prepared filename
$this->_newFile = implode('/', $path) . $file; // the $file contains heading slash
return $this;
}
public function getBaseFile()
{
return $this->_baseFile;
}
public function getNewFile()
{
return $this->_newFile;
}
/**
* @return Mage_Catalog_Model_Product_Image
*/
public function setImageProcessor($processor)
{
$this->_processor = $processor;
return $this;
}
/**
* @return Varien_Image
*/
public function getImageProcessor()
{
if( !$this->_processor ) {
// var_dump($this->_checkMemory());
// if (!$this->_checkMemory()) {
// $this->_baseFile = null;
// }
$this->_processor = new Varien_Image($this->getBaseFile());
}
$this->_processor->keepAspectRatio($this->_keepAspectRatio);
$this->_processor->keepFrame($this->_keepFrame);
$this->_processor->keepTransparency($this->_keepTransparency);
$this->_processor->constrainOnly($this->_constrainOnly);
$this->_processor->backgroundColor($this->_backgroundColor);
$this->_processor->quality($this->_quality);
return $this->_processor;
}
/**
* @see Varien_Image_Adapter_Abstract
* @return Mage_Catalog_Model_Product_Image
*/
public function resize()
{
if (is_null($this->getWidth()) && is_null($this->getHeight())) {
return $this;
}
$this->getImageProcessor()->resize($this->_width, $this->_height);
return $this;
}
/**
* @return Mage_Catalog_Model_Product_Image
*/
public function rotate($angle)
{
$angle = intval($angle);
$this->getImageProcessor()->rotate($angle);
return $this;
}
/**
* Set angle for rotating
*
* This func actually affects only the cache filename.
*
* @param int $angle
* @return Mage_Catalog_Model_Product_Image
*/
public function setAngle($angle)
{
$this->_angle = $angle;
return $this;
}
/**
* Add watermark to image
* size param in format 100x200
*
* @param string $file
* @param string $position
* @param string $size
* @param int $width
* @param int $heigth
* @param int $imageOpacity
* @return Mage_Catalog_Model_Product_Image
*/
public function setWatermark($file, $position=null, $size=null, $width=null, $heigth=null, $imageOpacity=null)
{
if ($this->_isBaseFilePlaceholder)
{
return $this;
}
if ($file) {
$this->setWatermarkFile($file);
} else {
return $this;
}
if ($position)
$this->setWatermarkPosition($position);
if ($size)
$this->setWatermarkSize($size);
if ($width)
$this->setWatermarkWidth($width);
if ($heigth)
$this->setWatermarkHeigth($heigth);
if ($imageOpacity)
$this->setImageOpacity($imageOpacity);
$filePath = $this->_getWatermarkFilePath();
if($filePath) {
$this->getImageProcessor()
->setWatermarkPosition( $this->getWatermarkPosition() )
->setWatermarkImageOpacity( $this->getWatermarkImageOpacity() )
->setWatermarkWidth( $this->getWatermarkWidth() )
->setWatermarkHeigth( $this->getWatermarkHeigth() )
->watermark($filePath);
}
return $this;
}
/**
* @return Mage_Catalog_Model_Product_Image
*/
public function saveFile()
{
$filename = $this->getNewFile();
$this->getImageProcessor()->save($filename);
Mage::helper('core/file_storage_database')->saveFile($filename);
return $this;
}
/**
* @return string
*/
public function getUrl()
{
$baseDir = Mage::getBaseDir('media');
$path = str_replace($baseDir . DS, "", $this->_newFile);
return Mage::getBaseUrl('media') . str_replace(DS, '/', $path);
}
public function push()
{
$this->getImageProcessor()->display();
}
/**
* @return Mage_Catalog_Model_Product_Image
*/
public function setDestinationSubdir($dir)
{
$this->_destinationSubdir = $dir;
return $this;
}
/**
* @return string
*/
public function getDestinationSubdir()
{
return $this->_destinationSubdir;
}
public function isCached()
{
return $this->_fileExists($this->_newFile);
}
/**
* Set watermark file name
*
* @param string $file
* @return Mage_Catalog_Model_Product_Image
*/
public function setWatermarkFile($file)
{
$this->_watermarkFile = $file;
return $this;
}
/**
* Get watermark file name
*
* @return string
*/
public function getWatermarkFile()
{
return $this->_watermarkFile;
}
/**
* Get relative watermark file path
* or false if file not found
*
* @return string | bool
*/
protected function _getWatermarkFilePath()
{
$filePath = false;
if (!$file = $this->getWatermarkFile())
{
return $filePath;
}
$baseDir = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath();
if( $this->_fileExists($baseDir . '/watermark/stores/' . Mage::app()->getStore()->getId() . $file) ) {
$filePath = $baseDir . '/watermark/stores/' . Mage::app()->getStore()->getId() . $file;
} elseif ( $this->_fileExists($baseDir . '/watermark/websites/' . Mage::app()->getWebsite()->getId() . $file) ) {
$filePath = $baseDir . '/watermark/websites/' . Mage::app()->getWebsite()->getId() . $file;
} elseif ( $this->_fileExists($baseDir . '/watermark/default/' . $file) ) {
$filePath = $baseDir . '/watermark/default/' . $file;
} elseif ( $this->_fileExists($baseDir . '/watermark/' . $file) ) {
$filePath = $baseDir . '/watermark/' . $file;
} else {
$baseDir = Mage::getDesign()->getSkinBaseDir();
if( $this->_fileExists($baseDir . $file) ) {
$filePath = $baseDir . $file;
}
}
return $filePath;
}
我想你可以使用
echo Mage::getModel('catalog/product_media_config')
->getMediaUrl( $product->getImage() );
也可以使用getSmallImage()
或getThumbnail()
方法。
你使用的是什么版本的M2e Pro,我目前的版本是6,它可以选择使用基本图像而不是图库。在我的magento 1.6.2.0中效果很好,如果你的基础图像至少有500像素