Magento向管理订单网格添加付款方式

Ste*_*ell 7 magento

我正在尝试将自定义列添加到"销售订单"网格,并且我已将连接和列添加到集合中,但该列显示为空.此外,当我尝试过滤时,我收到此错误:未找到列:1054'where子句'中的未知列'方法'.我的代码似乎与大多数教程中的代码相同,所以我无法弄清楚为什么我的专栏没有任何支付数据.我回应了最终的SQL查询并在MySQL Workbench中运行它,结果和语法似乎没问题.我错过了什么吗?我是否需要在sales_flat_order_grid表中添加一列?我意识到,当我去过滤器时,我的"漂亮"付款方式名称可能与我在列中显示的付款代码很不相符,但在过滤器选项中使用付款代码时我遇到了同样的问题.在我得到一些列数据后,我想我会在稍后详细说明.我使用的是Enterprise 1.12.0.2.

应用程序/代码/本地/ mymodule中/ adminhtml /块/销售/顺序/格:

     protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()->joinLeft(array('sfop'=>'sales_flat_order_payment'), 'main_table.entity_id = sfop.parent_id',array('sfop.method'));
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

     protected function _prepareColumns()
{  //edited for brevity...only my additions below![enter image description here][1]
         $payments = Mage::getSingleton('payment/config')->getActiveMethods();
    $methods = array();
    foreach ($payments as $paymentCode=>$paymentModel)
    {
        $paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
        $methods[$paymentCode] = $paymentTitle;
    }

    $this->addColumn('method', array(
        'header' => Mage::helper('sales')->__('Payment Method'),
        'index' => 'method',
        'filter_index' => 'sfop.method',
        'type'  => 'options',
        'width' => '70px',
        'options' => $methods,
    ));

}
Run Code Online (Sandbox Code Playgroud)

管理员屏幕

Mea*_*bed 6

您需要返回Admin Grid的父级而不是您要重写的类的父级.

将方法_prepareCollection()替换为以下内容: -

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->join(array('payment'=>'sales/order_payment'),'main_table.entity_id=parent_id','method');
    $this->setCollection($collection);
    return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
}
Run Code Online (Sandbox Code Playgroud)