Change Dashboard Chart in Magento Version 1.7 / 1.12

In previous versions of Magento (1.6 and earlier for CE, 1.11 and earlier for EE), the graph on the admin control panel reflected the number of accepted orders accepted. Starting from 1.7 / 1.12, this has now been changed to reflect orders that have been invoiced. We use custom statuses and, for example, the Dashboard chart as a report on the fast heart rate of sales. However, none of our orders ever reach invoice status due to the way we process the processing of the final order (and not through Magento)

How can I change the dashboard schedule to report processing, Invoiced and our custom order status? Our user status is tied to processing, so I may only need a request for processing and billing. According to Magento Support, such a modification is possible, but I'm not sure where to start looking besides the file /app/design/Adminhtml/default/default/template/dashboard/graph.phtml. Thanks!

+1
source share
3 answers

Oleg Ishchenkoโ€™s answer indicates that you are in the right direction, but not completely exhaustive. 1. In the module you are creating, you need to override Mage_Reports_Model_Resource_Order_Collection : so in config.xml put:

 ... <global> <models> <yourmodule> <class>Namespace_Yourmodule_Model</class> </yourmodule> <reports_resource> <rewrite> <order_collection>Namespace_Yourmodule_Model_Reports_Resource_Order_Collection</order_collection> </rewrite> </reports_resource> </models> </global> ... 

2. Then create a class (respecting the path), and in this class you need to override 2 methods:

 <?php /** * Show all orders, not only the invoiced one */ class Namespace_Yourmodule_Model_Reports_Resource_Order_Collection extends Mage_Reports_Model_Resource_Order_Collection { protected function _prepareSummaryLive($range, $customStart, $customEnd, $isFilter = 0) { $this->setMainTable('sales/order'); $adapter = $this->getConnection(); /** * Reset all columns, because result will group only by 'created_at' field */ $this->getSelect()->reset(Zend_Db_Select::COLUMNS); $expression = sprintf('%s - %s - %s - (%s - %s - %s)', $adapter->getIfNullSql('main_table.base_total_invoiced', 0), $adapter->getIfNullSql('main_table.base_tax_invoiced', 0), $adapter->getIfNullSql('main_table.base_shipping_invoiced', 0), $adapter->getIfNullSql('main_table.base_total_refunded', 0), $adapter->getIfNullSql('main_table.base_tax_refunded', 0), $adapter->getIfNullSql('main_table.base_shipping_refunded', 0) ); if ($isFilter == 0) { $this->getSelect()->columns(array( 'revenue' => new Zend_Db_Expr( sprintf('SUM((%s) * %s)', $expression, $adapter->getIfNullSql('main_table.base_to_global_rate', 0) ) ) )); } else { $this->getSelect()->columns(array( 'revenue' => new Zend_Db_Expr(sprintf('SUM(%s)', $expression)) )); } $dateRange = $this->getDateRange($range, $customStart, $customEnd); $tzRangeOffsetExpression = $this->_getTZRangeOffsetExpression( $range, 'created_at', $dateRange['from'], $dateRange['to'] ); $this->getSelect() ->columns(array( 'quantity' => 'COUNT(main_table.entity_id)', 'range' => $tzRangeOffsetExpression, )) //BOF modification // ->where('main_table.state NOT IN (?)', array( // Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, // Mage_Sales_Model_Order::STATE_NEW) // ) //EOF modification ->order('range', Zend_Db_Select::SQL_ASC) ->group($tzRangeOffsetExpression); $this->addFieldToFilter('created_at', $dateRange); return $this; } protected function _calculateTotalsLive($isFilter = 0) { $this->setMainTable('sales/order'); $this->removeAllFieldsFromSelect(); $adapter = $this->getConnection(); $baseTotalInvoiced = $adapter->getIfNullSql('main_table.base_grand_total', 0); $baseTotalRefunded = $adapter->getIfNullSql('main_table.base_discount_refunded', 0); $baseTaxInvoiced = $adapter->getIfNullSql('main_table.base_tax_amount', 0); $baseTaxRefunded = $adapter->getIfNullSql('main_table.base_tax_refunded', 0); $baseShippingInvoiced = $adapter->getIfNullSql('main_table.base_shipping_amount', 0); $baseShippingRefunded = $adapter->getIfNullSql('main_table.base_shipping_refunded', 0); $revenueExp = sprintf('%s - %s - %s - (%s - %s - %s)', $baseTotalInvoiced, $baseTaxInvoiced, $baseShippingInvoiced, $baseTotalRefunded, $baseTaxRefunded, $baseShippingRefunded ); $taxExp = sprintf('%s - %s', $baseTaxInvoiced, $baseTaxRefunded); $shippingExp = sprintf('%s - %s', $baseShippingInvoiced, $baseShippingRefunded); if ($isFilter == 0) { $rateExp = $adapter->getIfNullSql('main_table.base_to_global_rate', 0); $this->getSelect()->columns( array( 'revenue' => new Zend_Db_Expr(sprintf('SUM((%s) * %s)', $revenueExp, $rateExp)), 'tax' => new Zend_Db_Expr(sprintf('SUM((%s) * %s)', $taxExp, $rateExp)), 'shipping' => new Zend_Db_Expr(sprintf('SUM((%s) * %s)', $shippingExp, $rateExp)) ) ); } else { $this->getSelect()->columns( array( 'revenue' => new Zend_Db_Expr(sprintf('SUM(%s)', $revenueExp)), 'tax' => new Zend_Db_Expr(sprintf('SUM(%s)', $taxExp)), 'shipping' => new Zend_Db_Expr(sprintf('SUM(%s)', $shippingExp)) ) ); } $this->getSelect()->columns(array( 'quantity' => 'COUNT(main_table.entity_id)' )); //BOF modification // ->where('main_table.state NOT IN (?)', array( // Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, // Mage_Sales_Model_Order::STATE_NEW) // ); //EOF modification return $this; } } 

In this example, I placed filtering by order status, but you can easily not use it and put order statuses that you do not want to take into account.

NTN

+3
source

I did some digging, and it looks like the collection is being built in Mage_Reports_Model_Resource_Order_Collection::_prepareSummaryLive() . In Magento 1.7.0.2, the restriction is based on orders that are not specified in stati Mage_Sales_Model_Order::STATE_PENDING_PAYMENT or Mage_Sales_Model_Order::STATE_NEW .

Anyway, collection filters can be manipulated here (also see class file on github ):

 $this->getSelect() ->columns(array( 'quantity' => 'COUNT(main_table.entity_id)', 'range' => $tzRangeOffsetExpression, )) ->where('main_table.state NOT IN (?)', array( Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, Mage_Sales_Model_Order::STATE_NEW) ) ->order('range', Zend_Db_Select::SQL_ASC) ->group($tzRangeOffsetExpression); 

Any proposed manipulations, of course, are rewritable classes :)

+1
source

I found one proposed solution, but I have not much success in applying it. If anyone else can verify that this is a possible solution, I will modify this answer to reflect this. I will also modify the answer to apply the change correctly without changing the main file.


Open /app/code/core/Mage/Adminhtml/Block/Dashboard/Orders/Grid.php and add
 $collection->addAttributeToFilter('state', Mage_Sales_Model_Order::STATE_PROCESSING); 

AFTER

 $collection = Mage::getResourceModel('reports/order_collection') ->addItemCountExpr() ->joinCustomerName('customer') ->orderByCreatedAt(); 
0
source

All Articles