0
votes

I'm trying to display payment option on the grid of Orders and Invoices (in back-end).

I've copied core files

app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php

to local folder and then edit functions _prepareCollection() and _prepareColumns(). Prepare columns is a no-brainer, problem is in collection.

My changes:

File: app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php

protected function _prepareCollection(){
    $collection = Mage::getResourceModel($this->_getCollectionClass());

    $collection->getSelect()->joinLeft('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id',array('total_qty_ordered', 'shipping_description'));
    $collection->getSelect()->joinLeft('sales_flat_order_payment', 'sales_flat_order_payment.parent_id = main_table.entity_id',array('method'));    


    // this is custom function that retrieves an array with payment option and its label
    $metode = $this->getActivePaymentMethods();

    // we get labels of payment options
    foreach ($collection as $afn) {
        foreach ($metode as $method) {
            if ($method['value'] == $afn['method']) {
                $afn->setData('method', $method['label']);
            }
        }
    }

    $this->setCollection($collection);
    return parent::_prepareCollection();
}

This code actually does what is supposed to do. It retrieves payment and shipping option that was used on this order. But after, adding 'method' to collection it breaks the pagination and ordering.

It displays all orders on one page and no ordering works. It is the same with Invoices.

I've googled for an hour now without any luck. Can you please give me some direction where to look?

Thank you.

1
I already got that. It display the proper value. The problem is, that pagination is broken.Matic Krajnc
Yeah seems like this is correct. I just didn't understand it. Thanks!Matic Krajnc

1 Answers

0
votes

If i understood you right, you need substitute method id with it's label. You should do it in your grid _prepareColumns() method in next way:

    $this->addColumn('method', array(
        ...
        'type'  => 'options',
        'options' => array('method_id1' => 'label1', 'method_id2' => 'label2', ...),
    ));