0
votes

I have to develop a module to export collection of product,order,customer combined attributes. So i thought rather than modifying the core sales report for this purpose better to do a custom functionality. These are the steps that i did but i am not able to produce it. Used magento 1.4.1 version for this.

Under /var/www/magento141/app/code/core/Mage/Reports/etc/adminhtml.xml Added these lines for menus.

           <ereaders translate="title" module="reports">
                <title>Sales Report</title>                  
                 <children>
            <ereaders translate="title" module="reports">
                        <title>Sales Report</title>
                        <action>adminhtml/report_sales/ereaders</action>
                    </ereaders>
                </children>                                    
            </ereaders>

Under

/var/www/magento141/app/design/adminhtml/default/default/layout/sales.xml Added these lines for filter condition.

<adminhtml_report_sales_ereaders>
    <update handle="report_sales"/>
    <reference name="content">
        <block type="adminhtml/report_sales_sales" template="report/grid/container.phtml" name="sales.report.grid.container">
            <block type="adminhtml/store_switcher" template="report/store/switcher/enhanced.phtml" name="store.switcher">
                <action method="setStoreVarName"><var_name>store_ids</var_name></action>
            </block>
            <block type="sales/adminhtml_report_filter_form_order" name="grid.filter.form">
               ----
            </block>
        </block>
    </reference>
</adminhtml_report_sales_ereaders>

And then copied the needed block,model files from sales and renamed all of them into ereaders under /var/www/magento141/app/code/core/Mage/Adminhtml/.

Then placed action for ereaders under /var/www/magento141/app/code/core/Mage/Adminhtml/controllers/Report/SalesController.php

public function ereadersAction()
{
$this->_title($this->__('Reports'))->_title($this->__('Sales'))->_title($this->__('EReaders Sales'));

    $this->_showLastExecutionTime(Mage_Reports_Model_Flag::REPORT_ORDER_FLAG_CODE, 'ereaders');

    $this->_initAction()
        ->_setActiveMenu('report/sales/ereaders')
        ->_addBreadcrumb(Mage::helper('adminhtml')->__('EReaders Sales Report'), Mage::helper('adminhtml')->__('EReaders Sales Report'));

    $gridBlock = $this->getLayout()->getBlock('report_sales_ereaders.grid');
    $filterFormBlock = $this->getLayout()->getBlock('grid.filter.form');

    $this->_initReportAction(array(
        $gridBlock,
        $filterFormBlock
    ));
    $this->renderLayout();
}

Here when i use var_dump ==> //var_dump($this->getLayout()->getBlock('report_sales_ereaders.grid')); am getting bool(false) only. It does not call the ereaders grid, instead of its still loading blocks and grids from Sales only.

I searched most of the files related to report, am not still able to find out the problem. Hope many of you gone through these sort of issues, please can anyone tell me where am making mistake or missing something.

2

2 Answers

1
votes

I don't see a block named "report_sales_ereaders.grid" in your layout file, if that's the name you want to use, you should change "sales.report.grid.container" to "report_sales_ereaders.grid" in your layout. the getBlock method uses the name attribute in the layout file to load blocks from.

If you still have problems go into more detail about the blocks and models you copied in the background. hope this helps.

1
votes

You don't have the block named 'report_sales_ereaders.grid' because that block is created dynamically by Magento here:

// class Mage_Adminhtml_Block_Widget_Grid_Container
protected function _prepareLayout()
{
        $this->setChild( 'grid',
            $this->getLayout()->createBlock( $this->_blockGroup.'/' . $this->_controller . '_grid',
            $this->_controller . '.grid')->setSaveParametersInSession(true) );
        return parent::_prepareLayout();
}

$this->_controller is the key here. And you define it inside your block, which, seeing your sales.xml is "adminhtml/report_sales_sales".
That Block should extends from Mage_Adminhtml_Block_Widget_Grid_Container, and you should define ::_controller inside the contrusctor of that block:

public function __construct()
{
        $this->_blockGroup = 'something';
        $this->_controller = 'report_sales_ereaders';  // THIS !!!
        parent::__construct();
            ... // see a similar block from magento
}

Also note from the first code above (_prepareLayout) that Mage_Adminhtml_Block_Widget_Grid_Container will try to use a Block called (uri):

'something/report_sales_ereaders_grid'

so you need that class too, and therefore you probably want to change "something" with the node used in yout config.xml under <blocks>

that block will have the name (inside your layout): "report_sales_ereaders.grid"

So, depending what you want to do, you have two options here:

1) Change the type of your block in your sales.xml layout, so it points to your own block (and you define there your "_controller" how I showed above, etc).

2) Change

 $gridBlock = $this->getLayout()->getBlock('report_sales_ereaders.grid');      

to

 $gridBlock = $this->getLayout()->getBlock('report_sales_sales.grid');

because "report_sales_sales" is the value of "_controller" inside the block "adminhtml/report_sales_sales" (Mage_Adminhtml_Block_Report_Sales_Sales).