Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/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
Magento 如果我知道产品的id,我如何在小部件网格中打印产品的链接_Magento - Fatal编程技术网

Magento 如果我知道产品的id,我如何在小部件网格中打印产品的链接

Magento 如果我知道产品的id,我如何在小部件网格中打印产品的链接,magento,Magento,我在widget网格中有这个代码,在这个专栏中我有产品的id。我想打印链接到网格中的产品。我怎么能做到 我知道如何获得产品:$\u newProduct=Mage::getModel('catalog/product')->load($quote\u id) 谢谢 在网格中的列下方添加 … $this->addColumn('product_id', array( 'header' => $this->__('Product'),

我在widget网格中有这个代码,在这个专栏中我有产品的
id
。我想打印链接到网格中的产品。我怎么能做到

我知道如何获得产品:
$\u newProduct=Mage::getModel('catalog/product')->load($quote\u id)


谢谢

在网格中的列下方添加

   …
    $this->addColumn('product_id', array(
    'header' => $this->__('Product'),
                'align'  => 'center',
                'index'  => 'product_id',
                'width'  => '50px',
                'renderer'  => 'Namespace_Module_Block_Product'
    ));
    …   
现在,我们将创建参数渲染器中指示的块

<?php

class Namespace_Module_Block_Product extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{  

     public function render(Varien_Object $row)
     {
        $productId =  $row->getData($this->getColumn()->getIndex());
        $product = Mage::getModel('catalog/product')->load($productId);
        $link='<a href="' . $product->getProductUrl(); . '">'.$product->getName().'</a>';
        return $link;
     }
}

<?php

class Namespace_Module_Block_Product extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{  

     public function render(Varien_Object $row)
     {
        $productId =  $row->getData($this->getColumn()->getIndex());
        $product = Mage::getModel('catalog/product')->load($productId);
        $link='<a href="' . $product->getProductUrl(); . '">'.$product->getName().'</a>';
        return $link;
     }
}