1

I am working on a task to modify Date Range on Dashboard chart. Data chart will display on custom date range selection (Today/Yesterday/This Week/Last Week/This Month/Last Month).
I have extend the module from core (\app\code\core\Mage\Reports\Model\Resource\Order\Collection.php) to local (\app\code\local\Andi\Dashboard\Model\Reports\Resource\Order\Collection.php). I make changes to the getDateRange function.

Custom Admin Dashboard Date Range
I'm adding

case '2d':
            $dateEnd = Mage::app()->getLocale()->date();
            $dateEnd->addHour(1);
            $dateStart = clone $dateEnd;
            $dateStart->subDay(2);
            break;

for yesterday data.
2d means yesterday.
The condition is that the data shown today is the data of today's date only and does not include data from yesterday. Data shown yesterday was a day of data without the data the day before yesterday and today. So also with the data of the Week, Last Week, This Month, Last Month, This Year and Last Year.
I have debug it and get the following data:

$dateEnd = Mage::app()->getLocale()->date(); is Feb 12, 2015 7:56:15 PM
$dateEnd->addHour(1);                        is Feb 12, 2015 8:56:50 PM
$dateStart->subDay(2);                       is Feb 10, 2015 8:57:34 PM


How do I make by using addHour, subHour, addDay, subDay, addWeek, subWeek, addMonth, subMonth, addYear and subYear. Or can use this?

$current_time = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));
$yesterday = date("Y-m-d", Mage::getModel('core/date')->timestamp(time()-(60*60*24)));
0

The call Mage::app()->getLocale()->date() gives you an object of type Zend_Date. So your question regarding the additional methods like addHour and subDay deal with the Zend class Zend_Date, and not that much with Magento. The API page (http://framework.zend.com/manual/1.12/en/zend.date.overview.html) mentions the magic calls of sub() and add(), so my first reaction is that it should it be working as you mention it. However, I assume you have already tested this, and that it does not work in the way you want it to work. To overcome that, I would say you simply need to create a new class in your own custom Magento module (a helper for instance) that extends from Zend_Date so that you can implement those features you want to. Does that help?

  • Can you be more specific or can you give examples of cases showing only the data yesterday? I try to learn and modify from these extensions : magentocommerce.com/magento-connect/… – Andhi Irawan Feb 25 '15 at 6:33
  • @AndhiIrawan I'm not really familiar with those extensions, but as we have already worked out, this is not specific to extensions, but specific to the Zend Date API. As I mentioned, you could extend from this class to add your own calls - but this requires you to be familiar with overriding Zend classes (and not hacking them). Did you override something already? Otherwise, it might be quicker to work with basic PHP functions like strtotime() which accept arguments like "yesterday at 2 o clock". – Jisse Reitsma Feb 26 '15 at 16:00

Your Answer

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

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