0

I want to create a new report grid incl. filters in backend. The filters supposed to be period filters (date from/to, day/month/year) and show up in the grid header. Like product bestsellers. The columns itself should not contain any filters.

However, I have trouble to create the Grid.php because I'm not sure which class I should extend:

class MyModule_Namespace_Block_Adminhtml_Ordersummary_Grid 
    extends Mage_Adminhtml_Block_Widget_Grid {

The according template app/design/adminhtml/default/default/template/widget/grid.phtml does not contain any filters but at least I get the grid showing up.

If I use

class MyModule_Namespace_Block_Adminhtml_Ordersummary_Grid 
    extends Mage_Adminhtml_Block_Report_Grid_Abstract {

the page breaks after loading the container.phtml (just blank content and no footer). But the according template app/design/adminhtml/default/default/template/report/grid.phtml contains the filter options. So I assume I should use this?!

What class should I use? What am I doing wrong?

======

For the start I copied and pasted

app/code/core/Mage/Adminhtml/Block/Report/Sales/Bestsellers.php
app/code/core/Mage/Adminhtml/Block/Report/Sales/Bestsellers/Grid.php

app/code/local/MyModule/Namespace/Block/Adminhtml/Ordersummary/Grid.php

class MyModule_Namespace_Block_Adminhtml_Ordersummary_Grid  extends Mage_Adminhtml_Block_Report_Grid_Abstract 
{
protected $_columnGroupBy = 'period';

public function __construct()
{
    parent::__construct();
    $this->setCountTotals(true);
}

public function getResourceCollectionName()
{
    return 'sales/report_bestsellers_collection';
}

protected function _prepareColumns()
{
    $this->addColumn('period', array(
        'header'        => Mage::helper('sales')->__('Period'),
        'index'         => 'period',
        'width'         => 100,
        'sortable'      => false,
        'period_type'   => $this->getPeriodType(),
        'renderer'      => 'adminhtml/report_sales_grid_column_renderer_date',
        'totals_label'  => Mage::helper('adminhtml')->__('Total'),
        'html_decorators' => array('nobr'),
    ));

    $this->addColumn('product_name', array(
        'header'    => Mage::helper('sales')->__('Product Name'),
        'index'     => 'product_name',
        'type'      => 'string',
        'sortable'  => false
    ));

    if ($this->getFilterData()->getStoreIds()) {
        $this->setStoreIds(explode(',', $this->getFilterData()->getStoreIds()));
    }
    $currencyCode = $this->getCurrentCurrencyCode();

    $this->addColumn('product_price', array(
        'header'        => Mage::helper('sales')->__('Price'),
        'type'          => 'currency',
        'currency_code' => $currencyCode,
        'index'         => 'product_price',
        'sortable'      => false,
        'rate'          => $this->getRate($currencyCode),
    ));

    $this->addColumn('qty_ordered', array(
        'header'    => Mage::helper('sales')->__('Quantity Ordered'),
        'index'     => 'qty_ordered',
        'type'      => 'number',
        'total'     => 'sum',
        'sortable'  => false
    ));


    $this->addExportType('*/*/exportBestsellersCsv', Mage::helper('adminhtml')->__('CSV'));
    $this->addExportType('*/*/exportBestsellersExcel', Mage::helper('adminhtml')->__('Excel XML'));

    return parent::_prepareColumns();
}
}

app/code/local/MyModule/Namespace/Block/Adminhtml/Ordersummary.php

class MyModule_Namespace_Block_Adminhtml_Ordersummary extends Mage_Adminhtml_Block_Widget_Grid_Container
{

public function __construct()
{
    $this->_controller = 'report_sales_bestsellers';
    $this->_headerText = Mage::helper('sales')->__('Products Bestsellers Report');
    parent::__construct();
    $this->setTemplate('report/grid/container.phtml');
    $this->_removeButton('add');
    $this->addButton('filter_form_submit', array(
        'label'     => Mage::helper('reports')->__('Show Report'),
        'onclick'   => 'filterFormSubmit()'
    ));
}

public function getFilterUrl()
{
    $this->getRequest()->setParam('filter', null);
    return $this->getUrl('*/*/bestsellers', array('_current' => true));
}
}   

app/design/adminhtml/default/default/layout/mymodule_namespace.xml

    <adminhtml_namespace_reports_ordersummary>
    <reference name="content">
        <block type="namespace/adminhtml_ordersummary" template="report/grid/container.phtml"></block>
    </reference>    
</adminhtml_namespace_reports_ordersummary>

Your Answer

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

Browse other questions tagged or ask your own question.