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

时间:2013-07-26 17:49:37

标签: 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,
    ));

}

Admin Screen

4 个答案:

答案 0 :(得分: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();
}

答案 1 :(得分:2)

$collection->getSelect()->joinLeft('sales_flat_order_payment', 'main_table.entity_id = sales_flat_order_payment.parent_id',array('method'));
$this->addColumn('method', array(
        'header' => Mage::helper('sales')->__('Method'),
        'index' => 'method',
        'filter_index' => 'sales_flat_order_payment.method',
        ));

答案 2 :(得分:2)

提出的解决方案:

http://www.atwix.com/magento/column-to-orders-grid/

更干净。

无论如何,如果在网站范围内启用了付款方式,那么检索$ methods作为后端网格选项的方式不是多线存储的。在这种情况下,请执行:

        $methods = array();
        foreach (Mage::app()->getStores() as $storeId => $store) {
        $payments = Mage::getSingleton('payment/config')->getActiveMethods($storeId);

        foreach ($payments as $paymentCode => $paymentModel) {
            $paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
            if (!isset($methods[$paymentCode])) {
                $methods[$paymentCode] = $paymentTitle;
            }
        }
    }

答案 3 :(得分:1)

对于渲染,并非所有付款方式都使用标题(例如TIG PostNL)

$payments = Mage::getSingleton('payment/config')->getActiveMethods();
$methods = array();
foreach ($payments as $paymentCode=>$paymentModel)
{
    $paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title', 1);
    if(empty($paymentTitle)) {
        $paymentTitle = Mage::helper('payment')->getMethodInstance($paymentCode)->getTitle();
    }
    $methods[$paymentCode] = $paymentTitle;
}