Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 打电话获取类别图像&;在列表中显示_Image_List_Magento_Categories - Fatal编程技术网

Image 打电话获取类别图像&;在列表中显示

Image 打电话获取类别图像&;在列表中显示,image,list,magento,categories,Image,List,Magento,Categories,我目前已经设置好在magento自定义网格中显示我的目录图像-我似乎很接近,但似乎无法调用最终图像url来显示-有人能帮我吗 我也尝试过从/media/remote/cache给他们打电话,但没有用:-( 公共函数渲染(Varien_对象$row){ $p=Mage::getModel('catalog/product')->load($row->getproduct_id()); $html='getname()'。“/>”; 返回$html; } 您必须创建自定义渲染,如下所示 只需将其添加

我目前已经设置好在magento自定义网格中显示我的目录图像-我似乎很接近,但似乎无法调用最终图像url来显示-有人能帮我吗

我也尝试过从/media/remote/cache给他们打电话,但没有用:-(

公共函数渲染(Varien_对象$row){

$p=Mage::getModel('catalog/product')->load($row->getproduct_id());
$html='getname()'。“/>”;
返回$html;
}

您必须创建自定义渲染,如下所示

只需将其添加到网格中

  $this->addColumn('thumbnail',
                array(
                    'header'=> Mage::helper('catalog')->__('Thumbnail'),
                    'type'  => 'image',
                    'width' => '100',
                    'index' => 'thumbnail',
                    'renderer' => 'NAMESPACE_YOURMODULE_Block_Widget_Grid_Column_Renderer_Image',
            ));
并在上创建渲染类

\NAMESPACE\YOURMODULE\Block\Widget\Grid\Column\Renderer\Image.php
并使用正确的类名将下面的代码添加到此文件

class NAMESPACE_YOURMODULE_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 $imagesWidth = null;
protected static $imagesHeight = null;
protected static $imagesScale = null;

public function render(Varien_Object $row)
{
    return $this->_getValue($row);
}

protected static function initSettings()
{
    if(!self::$showImagesUrl)
        self::$showImagesUrl = (int)Mage::getStoreConfig('yourmodule/images/showurl') === 1;
    if(!self::$showByDefault)
        self::$showByDefault = (int)Mage::getStoreConfig('yourmodule/images/showbydefault') === 1;
    if(!self::$imagesWidth)
        self::$imagesWidth = Mage::getStoreConfig('yourmodule/images/width');
    if(!self::$imagesHeight)
        self::$imagesHeight = Mage::getStoreConfig('yourmodule/images/height');
    if(!self::$imagesScale)
        self::$imagesScale = Mage::getStoreConfig('yourmodule/images/scale');
}



protected function _getValue(Varien_Object $row)
{
    self::initSettings();

    $noSelection    =   false;
    $dored          =   false;
    if ($getter = $this->getColumn()->getGetter())
    {
        $val = $row->$getter();
    }

    $val = $val2 = $row->getData($this->getColumn()->getIndex());
    $noSelection = ($val == 'no_selection' || $val == '') ? true : $noSelection;
    $url = Mage::helper('yourmodule')->getImageUrl($val);

    if(!Mage::helper('yourmodule')->getFileExists($val)) 
    {
      $dored = true;
      $val .= "[*]";
    }

    $dored = (strpos($val, "placeholder/")) ? true : $dored;
    $filename = (!self::$showImagesUrl) ? '' : substr($val2, strrpos($val2, "/")+1, strlen($val2)-strrpos($val2, "/")-1);

    $val = ($dored) ? 
            ("<span style=\"color:red\" id=\"img\">$filename</span>") :
            "<span>". $filename ."</span>";

    $out = (!$noSelection) ? 
            ($val. '<center><a href="#" onclick="window.open(\''. $url .'\', \''. $val2 .'\')" title="'. $val2 .'" '. ' url="'.$url.'" id="imageurl">') :
            '';

    $outImagesWidth = self::$imagesWidth ? "width='".self::$imagesWidth."'":'';
    if(self::$imagesScale)
        $outImagesHeight = (self::$imagesHeight) ? "height='".self::$imagesHeight."'":'';
    else
        $outImagesHeight = (self::$imagesHeight && !self::$imagesWidth) ? "height='".self::$imagesHeight."'":'';

    //return '<img src="'.(Mage::helper("catalog/image")->init($productItem, "small_image")->resize(self::$imagesWidth)).'" '.$outImagesWidth.' '.$outImagesHeight.' alt="" />';




     $out .= (!$noSelection) ? 
                "<img src=".(Mage::helper("catalog/image")->init($row, $this->getColumn()->getIndex())->resize(self::$imagesWidth))." ".$outImagesWidth." ".$outImagesHeight." border=\"0\"/>" :
//                "<img src=".$url." ".$outImagesWidth." ".$outImagesHeight." border=\"0\"/>" :
//                "" :
                "<center><strong>[".__('NO IMAGE')."]</strong></center>";

        return $out. ((!$noSelection)? '</a></center>' : '');
    }
类名称空间\u模块\u块\u小部件\u网格\u列\u渲染器\u图像
扩展Mage\u Adminhtml\u Block\u Widget\u Grid\u Column\u Renderer\u Abstract
{
受保护的静态$showImagesUrl=null;
受保护的静态$showByDefault=null;
受保护的静态$imagesWidth=null;
受保护的静态$imagesHeight=null;
受保护的静态$imagescale=null;
公共函数渲染(Varien_对象$row)
{
返回$this->\u getValue($row);
}
受保护的静态函数initSettings()
{
如果(!self::$showImagesUrl)
self::$showmagesurl=(int)Mage::getStoreConfig('yourmodule/images/showurl')==1;
如果(!self::$showByDefault)
self::$showByDefault=(int)Mage::getStoreConfig('yourmodule/images/showByDefault')==1;
如果(!self::$imagesWidth)
self::$imagesWidth=Mage::getStoreConfig('yourmodule/images/width');
如果(!self::$imagesHeight)
self::$imagesHeight=Mage::getStoreConfig('yourmodule/images/height');
如果(!self::$imagescale)
self::$imagescale=Mage::getStoreConfig('yourmodule/images/scale');
}
受保护函数_getValue(变量对象$row)
{
self::initSettings();
$noSelection=false;
$dored=false;
如果($getter=$this->getColumn()->getGetter())
{
$val=$row->$getter();
}
$val=$val2=$row->getData($this->getColumn()->getIndex());
$noSelection=($val=='no| |$val=='')true:$noSelection;
$url=Mage::helper('yourmodule')->getImageUrl($val);
如果(!Mage::helper('yourmodule')->getFileExists($val))
{
$dored=true;
$val.=“[*]”;
}
$dored=(strpos($val,“占位符/”)true:$dored;
$filename=(!self::$showImagesUrl)?“”:substr($val2,strrpos($val2,“/”)+1,strlen($val2)-strrpos($val2,“/”)-1;
$val=($dored)?
(“$filename”):
“.$filename.”;
$out=(!$noSelection)?
($val.:'');
}

希望这一定会对您有所帮助。

我似乎没有任何运气使用这一个-我在过去使用过:您可以使用像echo Mage::helper('catalog/image')->init($products,'small_image')->resize(163100);//如果您有产品集合对象,$products=Mage::getModel,则使用resize函数调整图像大小('catalog/product')->load(1);//product id直到运气不好为止这是怎么回事?再近一点?$p=Mage::getModel('catalog/product')->load($row->getproduct_id());$html='getsmall_image()。'width=“50”height=“50”alt=“”。$p->getname()。“/>”;返回$html;其中$row->getproduct_id()应该是从for循环作为集合对象吗?请参阅,这肯定会对您有所帮助
class NAMESPACE_YOURMODULE_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 $imagesWidth = null;
protected static $imagesHeight = null;
protected static $imagesScale = null;

public function render(Varien_Object $row)
{
    return $this->_getValue($row);
}

protected static function initSettings()
{
    if(!self::$showImagesUrl)
        self::$showImagesUrl = (int)Mage::getStoreConfig('yourmodule/images/showurl') === 1;
    if(!self::$showByDefault)
        self::$showByDefault = (int)Mage::getStoreConfig('yourmodule/images/showbydefault') === 1;
    if(!self::$imagesWidth)
        self::$imagesWidth = Mage::getStoreConfig('yourmodule/images/width');
    if(!self::$imagesHeight)
        self::$imagesHeight = Mage::getStoreConfig('yourmodule/images/height');
    if(!self::$imagesScale)
        self::$imagesScale = Mage::getStoreConfig('yourmodule/images/scale');
}



protected function _getValue(Varien_Object $row)
{
    self::initSettings();

    $noSelection    =   false;
    $dored          =   false;
    if ($getter = $this->getColumn()->getGetter())
    {
        $val = $row->$getter();
    }

    $val = $val2 = $row->getData($this->getColumn()->getIndex());
    $noSelection = ($val == 'no_selection' || $val == '') ? true : $noSelection;
    $url = Mage::helper('yourmodule')->getImageUrl($val);

    if(!Mage::helper('yourmodule')->getFileExists($val)) 
    {
      $dored = true;
      $val .= "[*]";
    }

    $dored = (strpos($val, "placeholder/")) ? true : $dored;
    $filename = (!self::$showImagesUrl) ? '' : substr($val2, strrpos($val2, "/")+1, strlen($val2)-strrpos($val2, "/")-1);

    $val = ($dored) ? 
            ("<span style=\"color:red\" id=\"img\">$filename</span>") :
            "<span>". $filename ."</span>";

    $out = (!$noSelection) ? 
            ($val. '<center><a href="#" onclick="window.open(\''. $url .'\', \''. $val2 .'\')" title="'. $val2 .'" '. ' url="'.$url.'" id="imageurl">') :
            '';

    $outImagesWidth = self::$imagesWidth ? "width='".self::$imagesWidth."'":'';
    if(self::$imagesScale)
        $outImagesHeight = (self::$imagesHeight) ? "height='".self::$imagesHeight."'":'';
    else
        $outImagesHeight = (self::$imagesHeight && !self::$imagesWidth) ? "height='".self::$imagesHeight."'":'';

    //return '<img src="'.(Mage::helper("catalog/image")->init($productItem, "small_image")->resize(self::$imagesWidth)).'" '.$outImagesWidth.' '.$outImagesHeight.' alt="" />';




     $out .= (!$noSelection) ? 
                "<img src=".(Mage::helper("catalog/image")->init($row, $this->getColumn()->getIndex())->resize(self::$imagesWidth))." ".$outImagesWidth." ".$outImagesHeight." border=\"0\"/>" :
//                "<img src=".$url." ".$outImagesWidth." ".$outImagesHeight." border=\"0\"/>" :
//                "" :
                "<center><strong>[".__('NO IMAGE')."]</strong></center>";

        return $out. ((!$noSelection)? '</a></center>' : '');
    }