I've added a custom attribute to the sales_order_flat
table, and I'm trying to display this attribute in the grid at sales_order/index
.
I've done this with customer attributes successfully, but I'm getting errors when trying the same thing with order data.
<global>
<blocks>
<adminhtml>
<rewrite>
<sales_order_grid>WACI_AdminHtmlExt_Block_Sales_Order_Grid</sales_order_grid>
</rewrite>
</adminhtml>
</blocks>
<!-- etc -->
app/code/local/namespace/module/Block/Sales/Order/Grid.php
class WACI_AdminHtmlExt_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{
protected function _prepareColumns()
{
$this->addColumn('dynamics_ord', array(
'header' => $this->__('Dynamics ID'),
'width' => '75px',
'index' => 'dynamics_ord',
));
$this->addColumnsOrder('dynamics_ord','entity_id');
return parent::_prepareColumns();
}
}
I see that _prepareCollection
is sometimes used, but I'm trying to just amend the collection during setCollection
for, if nothing else, simplicity.
Whatever the case, the column displays, but no data is produced. (And the page errors out when I try to sort).
Any ideas on this?
Update
This post is an extension of this SO thread I've updated it to match the modules current status. That is, I'm adding columns to both sales_flat_order
and sales_flat_order_grid
.
From that post, I've got an action that takes place to set this attribute value (after the order has been completed).
My question at this point is - how does updateGridRecords()
come into play?
=> updateGridRecords appears to be called automatically when the $order->save() gets called (something I'm doing manually after the order is complete).
If I understand this correctly, because I'm not pulling data from any other model, the _prepareColumns
call is all that's required.
=> yep. Displaying and sorting properly after the attr is saved. Win!