当我在后端添加新产品时,我被要求选择“相关产品”,“向上销售”和“交叉销售”。我希望能够在后端看到缩略图,这样我就可以快速选择它们,而不是试图通过名字/ sku来选择它们。
答案 0 :(得分:3)
adminhtml网格不存在渲染器图像。你必须覆盖它。
修改档案app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Related.php
附近的第140行,在此代码下:
$this->addColumn('entity_id', array(
'header' => Mage::helper('catalog')->__('ID'),
'sortable' => true,
'width' => 60,
'index' => 'entity_id'
));
粘贴此代码:
$this->addColumn('image', array(
'header'=> Mage::helper('catalog')->__('Image'),
'type' => 'image',
'width' => '60px',
'index' => 'image',
));
修改档案app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php
第271行,添加此代码以覆盖渲染器:
case 'image':
$rendererClass = 'adminhtml/widget_grid_column_renderer_image';
break;
和附近的348行添加(对于过滤器):
case 'image':
$filterClass = 'adminhtml/widget_grid_column_filter_image';
break;
现在,您必须使用以下内容代码创建文件app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Image.php
(如果不存在):
<?php class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Image extends
Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
protected static $showImagesUrl = null;
protected static $showByDefault = null;
protected static $width = null;
protected static $height = null;
public function __construct() {
if(self::$showImagesUrl == null)
self::$showImagesUrl = 1;
if(self::$showByDefault == null)
self::$showByDefault = 1;
if(self::$width == null)
self::$width = '60px';
if(self::$height == null)
self::$height = '60px';
}
/**
* Renders grid column
*
* @param Varien_Object $row
* @return string
*/
public function render(Varien_Object $row) {
return $this->_getValue($row);
}
/*
public function renderProperty(Varien_Object $row) {
$val = $row->getData($this->getColumn()->getIndex());
$val = Mage::helper('imagebyurl')->getImageUrl($val);
$out = parent::renderProperty(). ' onclick="showImage('.$val.')" ';
return $out;
}
*/
protected function _getValue(Varien_Object $row) {
//$row->getEntityId();
$dored = false;
if ($getter = $this->getColumn()->getGetter()) {
$val = $row->$getter();
}
$val = $val2 = $row->getData($this->getColumn()->getIndex());
$val = str_replace("no_selection", "", $val);
$val2 = str_replace("no_selection", "", $val2);
$url = Mage::helper('adminhtml')->getImageUrl($val);
if(!Mage::helper('adminhtml')->getFileExists($val)) {
$dored =true;
$val .= "[!]";
}
if(strpos($val, "placeholder/")) {
$dored = true;
}
$filename = substr($val2, strrpos($val2, "/")+1,
strlen($val2)-strrpos($val2, "/")-1);
$_url = $url;
//echo $_SERVER['SERVER_NAME'];
if(!self::$showImagesUrl) $filename = '';
if($dored) {
$val = "<span style=\"color:red\" id=\"img\">$filename</span>";
}
else {
$val = "<span style=\"color:#888;\">". $filename ."</span>";
}
if(empty($val2) ) {
$out = "<center>" . $this->__("(no image)") . "</center>";
}
else {
$out = $val. '<center><a href="'.$_url.'" target="_blank"
id="imageurl">';
}
if(self::$showByDefault && !empty($val2) ) {
$out .= "<img src=". $url ." width='60px' ";
$out .=" />";
}
$out .= '</a></center>';
return $out;
}
}
(您可以将width=60px
替换为您想要的任何宽度或添加高度)
现在,您必须使用以下内容代码创建文件app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Image.php
(如果不存在):
<?php class Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Text { }
别忘了刷新缓存。
现在您必须在相关网格中看到图像列。
您可以为app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Upsell.php
和app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Crosssell.php
答案 1 :(得分:0)
您可以覆盖显示管理员该区域中产品的网格控制器,并使用另一个显示产品图像的字段。