Modify admin dashboard’s default period time (“Select range”)

Hi,

by default on dashboard you will see results from last 24hours, if you want to have it by default in different time span than you will be in trouble as there is no facility to set it up.

You can do something however to remedy this, you will need to modify some core files, and as I do not suggest modifying original files we need to copy them to local code pool as described in this post.

Copy following files:

  1. magento\app\code\core\Mage\Adminhtml\Block\Dashboard\Tab\Amounts.php
  2. magento\app\code\core\Mage\Adminhtml\Block\Dashboard\Tab\Orders.php
  3. magento\app\code\core\Mage\Adminhtml\Helper\Dashboard\Data.php

into local code pool

  1. magento\app\code\local\Mage\Adminhtml\Block\Dashboard\Tab\Amounts.php
  2. magento\app\code\local\Mage\Adminhtml\Block\Dashboard\Tab\Orders.php
  3. magento\app\code\local\Mage\Adminhtml\Helper\Dashboard\Data.php

In first two the change is the same, update following line (line breaks added for clarity):

$this->getRequest()->getParam('period')?
$this->getRequest()->getParam('period'):'24h'

to be (line breaks added for clarity):

$this->getRequest()->getParam('period')?
$this->getRequest()->getParam('period'):'7d'

now save them, clear magento cache and see results, you should see graph in last 7 days state but the drop down displays last 24 hours. That is where the third file comes in, locate the getDatePeriods() function and swap first 2 entries to look like this:

    public function getDatePeriods()
    {
        return array(
            '7d'=>$this->__('Last 7 Days'),
            '24h'=>$this->__('Last 24 Hours'),
            '1m'=>$this->__('Current Month'),
            '1y'=>$this->__('YTD'),
            '2y'=>$this->__('2YTD')
        );
    }

If you don’t like this update (change to Data.php) you still make it work as you like:) go to the graph.phtml file located in following folder: magento\app\design\adminhtml\default\default\template\dashboard\ and put following changes:

somwhere above the line with:

<div style="margin:20px;">

put:

<?php
$localPeriod = $this->getRequest()->getParam('period');
switch ($localPeriod)
{
	case '24h':
	case '7d':
	case '1m':
	case '1y':
	case '2y':
		break;
	default:
		$localPeriod = '7d';
}

?>

then change this (line breaks added for clarity)

<?php if($this->getRequest()
->getParam('period')==$_value): ?>

into this

<?php if($localPeriod==$_value): ?>

now it will properly set as selected the last 7 days (or what ever you have set as default) option.

best regards

This entry was posted in magento, php and tagged , , , , , , , , . Bookmark the permalink.

1 Response to Modify admin dashboard’s default period time (“Select range”)

  1. Dirty Harry says:

    Hi All;

    Having wasted over a day in forums and reinstalling Magento three times the solution was very simple in the end.

    You do not have to modify any codes etc “Varien.php” just ensure your server has minimum of 46Meg memory and your problem will be resolved.

    Happy Days!!

Comments are closed.