Magento Products Sold Report – Understanding the Period Column

reports

I'm looking to create a custom Magento Adminhtml report based on the Products Sold report (Reports->Products->Products Ordered in Adminhtml). I can see that the Products Sold report's Grid Block is Mage_Adminhtml_Block_Report_Product_Sold_Grid.

However, I'm obviously missing something, because the report has a period column, which isn't added to the report in the Grid block's _prepareColumns() function. Here are the other two columns being added in Mage_Adminhtml_Block_Report_Product_Sold_Grid:

protected function _prepareColumns()
{
    $this->addColumn('name', array(
        'header'    =>Mage::helper('reports')->__('Product Name'),
        'index'     =>'order_items_name'
    ));

    $this->addColumn('ordered_qty', array(
        'header'    =>Mage::helper('reports')->__('Quantity Ordered'),
        'width'     =>'120px',
        'align'     =>'right',
        'index'     =>'ordered_qty',
        'total'     =>'sum',
        'type'      =>'number'
    ));

    $this->addExportType('*/*/exportSoldCsv', Mage::helper('reports')->__('CSV'));
    $this->addExportType('*/*/exportSoldExcel', Mage::helper('reports')->__('Excel XML'));

    return parent::_prepareColumns();
}

My question is where is the Period column is coming from, and from where is it getting its data?

Best Answer

Take a look at adminhtml/default/default/template/report/grid.phtml.
On line 136(Magento 1.7.0.2) the following statement starts a loop which outputs the individual rows: getCollection()->getIntervals() as $_index => $_item): ?>.
The $_index variable holds the time information. Than take a look at the parent class of Mage_Adminhtml_Block_Report_Product_Sold_Grid - Mage_Adminhtml_Block_Report_Grid.
On line 147 the following statement sets the time span of the report: $collection->setInterval($from, $to). Hope that this will help you! Regards

Related Topic