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.


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());


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.

$resourceCollection = Mage::getResourceModel($this->getResourceCollectionName()); 
$resourceCollection->join('catalog/product', 'product_id = entity_id', '*')

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.

  • Thanks for the reply. I will write a module and try this out. I'm guessing the process will be the same for the other reports? – Daniel West Jun 17 '15 at 19:35
  • 1
    It should be yes. Provided that the collection in use has entity_id as a column representing the product. I should expect all the product focused ones will have this. – John Cuthbert Jun 18 '15 at 6:55
  • Hi John, just looking into this now and there doesn't seem to be a _prepareCollection() function in Mage_Adminhtml_Block_Report_Sales_Bestsellers_Grid. There is only _prepareColumns(). – Daniel West Jun 22 '15 at 12:44
  • 1
    _prepareCollection is inherited from the parent class, Mage_Adminhtml_Block_Report_Grid_Abstract. By putting this within your class you are overriding the functionality to provide your custom collection loading. – John Cuthbert Jun 22 '15 at 12:52
  • Ah yeah just checked that now. Knew it would be something like that. So I really only need to add the join condition to the existing $resourceCollection object? – Daniel West Jun 22 '15 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.