Magento - Sales Orders Grid - Display Today's Orders Only

Posted on December 22, 2012 by Nimrod Techn There have been 0 comments

Typically, when a Magento store reaches 20,000 orders and more than 5 people load the sales-orders grid concurrently, our online store becomes extremely slow.

 

How do we solve it? simple. limiting the amount of orders presented in the orders grid for the last 24 hours, unless requested otherwise.

Copy the app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php file to:

app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php

Edit the following function, copy-paste from here:

protected function _prepareCollection()    {

$collection = Mage::getResourceModel($this->_getCollectionClass());

######################## FILTER BY LAST DAY ######################
$now = Mage::getModel('core/date')->timestamp(time());
$filter   = $this->getParam($this->getVarNameFilter(), null); //important - check for other requested grid-filters before filtering today's orders

$dateStart = date('Y-m-d' . ' 00:00:00', $now);
$dateEnd = date('Y-m-d' . ' 23:59:59', $now);
$postData = Mage::app()->getRequest()->getPost();
if (empty($filter)) {
$collection->addFieldToFilter('`main_table`.created_at', array('from' => $dateStart, 'to' => $dateEnd));
}
##################################################################

 

$collection->getSelect()->group('entity_id');
$this->setCollection($collection);

return $this;

}


This post was posted in Speeding Up your Magento Website

Magento is a well-engineered eCommerce platform designed to help engineers develop customized eCommerce online stores. Due to lack of proper coding documentation, Engineer-ing.com was created with the sole purpose of instructing Magento developers to-be with the "how-to-do" know-how. In the event of unresolved issues, you are more than welcome to contact me for consultation. However, please do so only if you possess a Software Engineering background and you're able to specify your question.