在发票网格中添加自定义列 - Magento 1

时间:2017-11-02 09:27:40

标签: php mysql magento

在Sales-> Invoice-> Invoice Grid中,我添加了一列付款方式。

在$ collection中,我加入了sales_flat_order_payment表,因此我可以拉出每个entity_id的方法并成功完成。当我回显查询并在Mysql中使用它时,它返回我想要的结果。

现在,我希望mysql的方法列在Invoice Grid中可见。

这就是我的所作所为。

我在这里执行了一些步骤。 Add custom renderer for a custom column in Magento grid

现在这是我的代码。

在我的

  

应用程序/代码/核心/法师/ Adminhtml /砌块/销售/发票/ Grid.php

这是我的$ collection

$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->join( array('a'=> mgmx_sales_flat_order_payment), 'a.entity_id = main_table.entity_id', array('a.method'));
$this->setCollection($collection);
/*echo $collection->getSelect();die();*/
return parent::_prepareCollection();

然后在_prepareColumns

$this->addColumn('payment_mode', array(
        'header'    => Mage::helper('sales')->__('Payment Mode'),
        'index'     => 'method',
        'renderer'  => 'Mage_Adminhtml_Block_Catalog_Product_Renderer_Red',
    ));

然后我在Renderer目录中创建一个Renderer Directoy和一个Red.php

  

应用程序/代码/核心/法师/ Adminhtml /砌块/销售/发票/渲染器

<?php 
class Mage_Adminhtml_Block_Catalog_Product_Renderer_Red extends 
  Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { 
  public function render(Varien_Object $row) { 
    $value =  $row->getData($this->getColumn()->getIndex());
  return $value;
 }
}
?>

但是这个会返回一个错误

  

致命错误:在第291行的/home/xxxxxxx/xxxx.xxxxxx.com/xxxxx/includes/src/Mage_Adminhtml_Block_Widget_Grid_Column.php中调用boolean上的成员函数setColumn()

2 个答案:

答案 0 :(得分:1)

为什么在添加新列时需要自定义渲染器?

如果您不需要任何自定义输出,请忽略渲染器:

<div class="data">
    <div class="data-item">
        <h6>'+data.title+'</h6>
        <ul>
            <li>contents from data2 value</li>
        </ul>
    <div>
<div>

答案 1 :(得分:1)

要修复您的示例,您必须更改渲染器的命名空间

你的班级路径是

app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Renderer

但您的班级名称是

Mage_Adminhtml_Block_Catalog_Product_Renderer_Red

这对于magento autoload永远不会有效。你必须把你的课程放到:

app/code/core/Mage/Adminhtml/Block/Catalog/Product/Renderer

(或完全更改班级名称,无论您喜欢什么)