To get all of the Skus in the order, you could use frame_callback
to look up the Skus for the order in a separate function.
In the _prepareColumns()
function for your Sku column:
...
$this->addColumn('increment_id', array(
'header' => Mage::helper('sales')->__('SKU'),
'index' => 'increment_id',
'frame_callback' => array($this, 'callback_skus')
));
...
Then add this new function somewhere in your Grid.php
.
public function callback_skus($value, $row, $column, $isExport) {
$increment_id = $value;
$_order = Mage::getModel('sales/order')->loadByIncrementId($increment_id);
$_items = $_order->getAllItems();
$skus="";
foreach ($_items as $item) {
$skus .= $item->getSku()."<br/>";
}
return $skus;
}
This will return all of the Skus for the order without a lot of complex joins.
EDIT - 2nd part of the answer
To enable searching/filtering on the above, you'll need to update the _prepareCollection()
to the following:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass())
->join(
'sales/order_item',
'`sales/order_item`.order_id=`main_table`.entity_id',
array(
'skus' => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR ",")'),
)
);
$collection->getSelect()->group('entity_id');
$this->setCollection($collection);
return parent::_prepareCollection();
}
Add a new function called filter_skus()
:
public function filter_skus($collection, $column) {
if (!$value = $column->getFilter()->getValue()) {
return $this;
}
$this->getCollection()->getSelect()->where(
"sku like ?"
, "%$value%");
return $this;
}
and update the addColumn
for sku
like this:
...
$this->addColumn('sku', array(
'header' => Mage::helper('sales')->__('SKU'),
'index' => 'increment_id',
'frame_callback' => array($this, 'callback_skus'),
'filter_condition_callback' => array($this, 'filter_skus'),
));
...
Notice the new call to filter_condition_callback
that adds the where
condition necessary to make the search function.