0

Hi All I am trying to develop a section on Magento Admin Dashboard Just Like Life time sales and Average orders. Example

enter image description here

I have overridden Dashboard.php block to add my custom block as its child in __prepareLayout() function Here is my dashboard.php code :

protected function _prepareLayout()
{
    $this->setChild('lastOrders',
            $this->getLayout()->createBlock('adminhtml/dashboard_orders_grid')
    );

    $this->setChild('totals',
            $this->getLayout()->createBlock('adminhtml/dashboard_totals')
    );

    $this->setChild('sales',
            $this->getLayout()->createBlock('adminhtml/dashboard_sales')
    );

    /* Here is my custom child block */

    $this->setChild('totalOrders',
            $this->getLayout()->createBlock('dashboard/adminhtml_totalorders')
    );

   /* custom code end here */

    $this->setChild('lastSearches',
            $this->getLayout()->createBlock('adminhtml/dashboard_searches_last')
    );

    $this->setChild('topSearches',
            $this->getLayout()->createBlock('adminhtml/dashboard_searches_top')
    );

    if (Mage::getStoreConfig(self::XML_PATH_ENABLE_CHARTS)) {
        $block = $this->getLayout()->createBlock('adminhtml/dashboard_diagrams');
    } else {
        $block = $this->getLayout()->createBlock('adminhtml/template')
            ->setTemplate('dashboard/graph/disabled.phtml')
            ->setConfigUrl($this->getUrl('adminhtml/system_config/edit', array('section'=>'admin')));
    }
    $this->setChild('diagrams', $block);

    $this->setChild('grids',
            $this->getLayout()->createBlock('adminhtml/dashboard_grids')
    );

    Mage_Adminhtml_Block_Template::_prepareLayout();
}

Here is my child block code :

class Custom_Dashboard_Block_Adminhtml_Totalorders extends Mage_Adminhtml_Block_Dashboard_Bar
{
    protected function _construct()
    {
        parent::_construct();
        $this->setTemplate('custom/dashboard/totalorders.phtml');
    }
}

I tried putting exit() or die() in my it and it worked child block is calling but i don't know why phtml is not loading.

My phtml path is design/adminhtml/default/default/template/custom/dashboard/totalorders.phtml

Here is my config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
    <Custom_Dashboard>
        <version>0.1.0</version>
    </Custom_Dashboard>
</modules>
<global>
    <blocks>
        <adminhtml>
            <rewrite>
                <dashboard>Custom_Dashboard_Block_Adminhtml_Dashboard</dashboard>
            </rewrite>
        </adminhtml>
        <dashboard>
            <class>Custom_Dashboard_Block</class>
        </dashboard>
    </blocks>
</global>
</config>

Any help Will be appreciable.

2
  • add you custom module config.xml code. Oct 25, 2016 at 6:23
  • Hello please check my question I updated it Oct 25, 2016 at 6:33

2 Answers 2

1

function _prepareLayout() generate layout for dashboard

class Mage_Adminhtml_Block_Dashboard extends Mage_Adminhtml_Block_Template
{
    protected function _prepareLayout()
    {
        $this->setChild('totals',$this->getLayout()->createBlock('adminhtml/dashboard_totals'));

    }
}

For display your template into dashboard you have to create block and set block as a child in _prepareLayou.

class Mage_Adminhtml_Block_Dashboard_Totals extends Mage_Adminhtml_Block_Dashboard_Bar
{
    protected function _construct()
    {
        parent::_construct();
        $this->setTemplate('dashboard/totalbar.phtml');
    }
}

you can set the template in _construct method of block

<div style="margin:20px;">
   <?php echo $this->getChildHtml('totals') ?>
</div>

all methods are set now call getChildHtml() in a dashboard to display your template.

0

Try this

$this->setChild('totalOrders',
            $this->getLayout()->createBlock('adminhtml/dashboard_totalorders')
    );
2
  • but the path of my block is local/custom/dashboard/block/adminhtml/totalorders Oct 25, 2016 at 6:03
  • and block is calling problem is with phtml file Oct 25, 2016 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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