I need to be able to add an SKU column to the Best Sellers report. I have managed to add the column to the page by adding:
$this->addColumn('sku', array(
'header' => Mage::helper('Sales')->__('Skus'),
'width' => '100px',
'index' => 'skus',
'type' => 'text',
));
to the _prepareColumns()
function but I cannot work out where I need to select the SKUs from in the Mage_Sales_Model_Resource_Report_Bestsellers
class.
Anyone have any ideas? Thanks in advance.
EDIT:
Added this join to _prepareColumns but still not getting any data:
$resourceCollection = Mage::getResourceModel($this->getResourceCollectionName());
$resourceCollection->join('catalog/product', 'product_id = entity_id', '*');
$resourceCollection->setPeriod($filterData->getData('period_type'));
$resourceCollection->setDateRange($filterData->getData('from', null), $filterData->getData('to', null));
$resourceCollection->addStoreFilter($storeIds);
$resourceCollection->setAggregatedColumns($this->_getAggregatedColumns());
Best Answer
What you will want to do is extend the Mage_Adminhtml_Block_Report_Sales_Bestsellers_Grid
Look at that class'es _prepareCollection() method
In your extended class, copy in the _prepareCollection() method, so you have a duplicate of it. Then modify it so that you are joining the product data against the collection.
This should give you into your collection sku, and a number of other product information which you may wish to refine since we're selecting * in this case.
Now you need your column to reference the new columns which have been selected:
$this->addColumn('sku', array( 'header' => Mage::helper('Sales')->__('Skus'), 'width' => '100px', 'index' => 'sku', 'type' => 'text', ));
Note the lack of plural on sku (not skus).
This should now render with your grid showing SKU as intended.