简体   繁体   English

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

[英]Magento Add Payment Method to Admin Order Grid

I am trying to add a custom column to the Sales Order grid and I have added the join and column to the collection, but the column shows empty. 我正在尝试将自定义列添加到“销售订单”网格,并且我已将连接和列添加到集合中,但该列显示为空。 Also, when I try to filter, I get this error: Column not found: 1054 Unknown column 'method' in 'where clause' . 此外,当我尝试过滤时,我收到此错误: 未找到列:1054'where子句'中的未知列'方法' My code seems to be the same as in the majority of tutorials out there, so I can't figure out why my column is devoid of any payment data. 我的代码似乎与大多数教程中的代码相同,所以我无法弄清楚为什么我的专栏没有任何支付数据。 I echoed the final SQL query and ran it in MySQL Workbench and the results and syntax seem to be fine. 我回应了最终的SQL查询并在MySQL Workbench中运行它,结果和语法似乎没问题。 Am I missing something? 我错过了什么吗? Do I need to add a column to the sales_flat_order_grid table? 我是否需要在sales_flat_order_grid表中添加一列? I realize that my "pretty" payment method names may not mesh well with the payment code I am displaying in the column when I go to filter, but I have the same issues when using payment code in the filter options. 我意识到,当我去过滤器时,我的“漂亮”付款方式名称可能与我在列中显示的付款代码很不相符,但在过滤器选项中使用付款代码时我遇到了同样的问题。 I figured I would hit that detail later, after I get some column data. 在我得到一些列数据后,我想我会在稍后详细说明。 I am using Enterprise 1.12.0.2. 我使用的是Enterprise 1.12.0.2。

app/code/local/mymodule/adminhtml/block/sales/order/grid: 应用程序/代码/本地/ 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,
    ));

}

管理员屏幕

You need to return the parent of the Admin Grid not the parent of the class you are rewriting. 您需要返回Admin Grid的父级而不是您要重写的类的父级。

Replace the method _prepareCollection() with the following:- 将方法_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();
}
$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',
        ));

The solution proposed in: 提出的解决方案:

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

is much cleaner. 更清洁。

Anyway the way to retrieve the $methods as options for the backend grid is not Multistore-ready if payment methods were enabled on website scope. 无论如何,如果在网站范围上启用了付款方式,那么检索$ methods作为后端网格选项的方式不是多线存储的。 In this case do: 在这种情况下做:

        $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;
            }
        }
    }

For the rendering, not all payment methods work with title (TIG PostNL for example) 对于渲染,并非所有付款方式都与标题一起使用(例如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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM