Magento module for changing dashboard diagrams

I am following this post Change the Dashboard chart in version 1.7 / 1.12 of Magento to allow the sale of "processing" orders on the graph toolbar. My files are located below and inside the correct directories, and also appear as active in config> advanced. I also reindexed, updated the cache, and updated the time statistics. I do not see errors in the logs. You see what is wrong? I have firegento and turned on logging, but this does not work.

EDIT: the amount of revenue on the toolbar seems correct, but it does not appear on the timeline chart. For example, there might be a clean 30-day order of $ 2,000 at 10am, but it does not appear on the timeline. Bounty for anyone who can fix the script below to think about a timeline for me!

CaitlinHavener / Control Panel / etc. /config.xml:

<?xml version="1.0"?> <config> <modules> <CaitlinHavener_Dashboard> <version>1.0</version> </CaitlinHavener_Dashboard> </modules> <global> <models> <CaitlinHavener_Dashboard> <class>CaitlinHavener_Dashboard_Model</class> </CaitlinHavener_Dashboard> <reports_resource> <rewrite> <order_collection>CaitlinHavener_Dashboard_Model_Reports_Resource_Order_Collection</order_collection> </rewrite> </reports_resource> </models> </global> </config> 

CaitlinHavener / Control Panel / Model / Reports / Resource / Order / Collection.php

  <?php /** * Show all orders, not only the invoiced one */ class CaitlinHavener_Dashboard_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) ); */ $expression = sprintf('%s - %s - %s - (%s - %s - %s)', $adapter->getIfNullSql('main_table.base_total_invoiced', 'main_table.base_grand_total'), $adapter->getIfNullSql('main_table.base_tax_invoiced', 'main_table.base_tax_amount'), $adapter->getIfNullSql('main_table.base_shipping_invoiced', 'main_table.base_shipping_amount'), $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); // $baseShippingRefunded = $adapter->getIfNullSql('main_table.base_shipping_refunded', 0); $baseTotalInvoiced = $adapter->getIfNullSql('main_table.base_total_invoiced', 'main_table.base_grand_total'); // This will check if there is no invoice it will calculate based on the grand totals ( so when you generate and invoice u will have no issues with the numbers also ) $baseTotalRefunded = $adapter->getIfNullSql('main_table.base_total_refunded', 0); $baseTaxInvoiced = $adapter->getIfNullSql('main_table.base_tax_invoiced', 'main_table.base_tax_amount'); // Same here for taxes $baseTaxRefunded = $adapter->getIfNullSql('main_table.base_tax_refunded', 0); $baseShippingInvoiced = $adapter->getIfNullSql('main_table.base_shipping_invoiced', 'main_table.base_shipping_amount'); // Same here for shipping $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)' )) ->where('main_table.state NOT IN (?)', array( Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, //Mage_Sales_Model_Order::STATE_NEW ) ); return $this; } } ?> 
+7
source share
1 answer

You need to understand the ordering process in Magento so that you can fully understand how the chart is filled.

  • Come to the store as a new order (for example, paid orders - Cash on delivery, ...) or a Pending order (orders for a credit card or PayPal, etc. are all online payment methods).
    • An order can be canceled at this stage (since the generated invoice is not created).
  • In the case of online payment, payment was successful (so the order is invoiced).
  • Order sent after invoicing (sent generated).
  • Return of the order (partial or full) generated by credit memos.

Now, if you look at the previous steps, and you will see that income should not be calculated if the order is in NEW and CANCELING STATE (not status)

It must be calculated when the order is billed (so that you receive a commission with income and delivery and refunds)

So, to count the orders in NEW STATE in revenue and schedule Override the method

 app/code/core/Mage/Reports/Model/Resource/Order/Collection.php /** * Calculate totals live report * * @param int $isFilter * @return Mage_Reports_Model_Resource_Order_Collection */ protected function _calculateTotalsLive($isFilter = 0){} 
  // Line 430 ->where('main_table.state NOT IN (?)', array( Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, Mage_Sales_Model_Order::STATE_NEW // Comment this line ) ); 

So now, if you comment on this line, the order will count towards (ORDERS chart graph)

but totals still not calculated (since there are no bills / shipments / refunds)

Thus, you need to change the calculation process using the invoice amount in order to use TOTALS only prior to the invoice. With minor changes, you can achieve what you want without error. Code below

Change the lines (390 and below) as follows:

 $baseTotalInvoiced = $adapter->getIfNullSql('main_table.base_total_invoiced', 'main_table.base_grand_total'); // This will check if there is no invoice it will calculate based on the grand totals ( so when you generate and invoice u will have no issues with the numbers also ) $baseTotalRefunded = $adapter->getIfNullSql('main_table.base_total_refunded', 0); $baseTaxInvoiced = $adapter->getIfNullSql('main_table.base_tax_invoiced', 'main_table.base_tax_amount'); // Same here for taxes $baseTaxRefunded = $adapter->getIfNullSql('main_table.base_tax_refunded', 0); $baseShippingInvoiced = $adapter->getIfNullSql('main_table.base_shipping_invoiced', 'main_table.base_shipping_amount'); // Same here for shipping $baseShippingRefunded = $adapter->getIfNullSql('main_table.base_shipping_refunded', 0); 

So, in a simple answer, the solution does not change the calculation method, but the solution changes the default values ​​for the calculations

Follow these changes and you will get exactly what you want :)

+4
source

All Articles