在“相关产品”上添加缩略图在 Magento 的后端

发布于 2024-10-08 01:41:38 字数 93 浏览 0 评论 0原文

当我在后端添加新产品时,系统会要求我选择“相关产品”、“向上销售”和“交叉销售”。我希望能够在后端看到缩略图,这样我就可以快速选择它们,而不是尝试按名称/sku 选择它们。

When I add a new product at the backend, I am asked to choose the "related products", "Up-sells" and "Cross-sells". I would like to be able to see the thumbnail images here at the backend, so I can choose them quickly, rather than trying to choose them by name/sku.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜血缘 2024-10-15 01:41:38

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.phpapp/code/core/Mage/Adminhtml 执行相同的操作/Block/Catalog/Product/Edit/Tab/Crosssell.php

Renderer image does not exist for adminhtml grid. You have to override this.

Edit file app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Related.php
nearby line 140, under this code:

$this->addColumn('entity_id', array(
    'header'    => Mage::helper('catalog')->__('ID'),
    'sortable'  => true,
    'width'     => 60,
    'index'     => 'entity_id'
));

Paste this code:

$this->addColumn('image', array(
    'header'=> Mage::helper('catalog')->__('Image'),
    'type'  => 'image',
    'width' => '60px',
    'index' => 'image',
));

Edit file app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column.php
line 271, add this code to override the renderer:

case 'image':
    $rendererClass = 'adminhtml/widget_grid_column_renderer_image';
    break;

and nearby line 348 add (for the filter):

case 'image':
    $filterClass = 'adminhtml/widget_grid_column_filter_image';
    break;

Now you must create file app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Image.php (if not exists) with this content code:

<?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;

            }
        }

(You can replace width=60px by any width you want or add height)

Now you must create file app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Filter/Image.php (if not exists) with this content code:

<?php class Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Text { }

Dont forget to refresh cache.

Now you must see an image column in the related grid.

You can do the same thing for app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Upsell.php and app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Crosssell.php

黑寡妇 2024-10-15 01:41:38

您可能可以使用另一个显示产品图像的字段来覆盖在管理的该区域中显示产品的网格控制器。

You could probably override a the grid controller that displays the products in that area of the admin with another field that shows you the image of the product.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文