Magento module to change dashboard graph

后端 未结 1 1953
孤城傲影
孤城傲影 2021-01-12 11:14

I am following along with this post Change the Dashboard Graph in version 1.7/1.12 of Magento to allow the sales of \"processing\" orders to show up on the dashboard graph.

相关标签:
1条回答
  • 2021-01-12 11:54

    You have to understand the Order process in Magento so you can fully understand how the chart being populated

    1. Order come to the Store as new Order ( like post paid orders - Cash on Delivery, ... ) or Pending order ( credit card orders or paypal etc.. all online payment methods ).
      • Order can be canceled at this step ( as no invoice generated ).
    2. In case of online payment, payment gone through successfully ( So the order is invoiced - invoice generated ).
    3. Order Shipped after being invoiced ( Shipment is generated ).
    4. Order refunded ( partial or complete ) so credit memos generated.

    Now if you look at the previous steps and you will see that the Revenue not supposed to be calculated if the Order is in NEW and CANCELED STATE ( not status )

    It should be calculated when the Order gets invoiced ( so you will get the revenue and shipping fees and the refunds )

    So to count the orders in NEW STATE in the revenue and the graph 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 this line the order Will be counted in the ( ORDERS chart graph )

    but the totals is still not calculated ( because there is no invoice / shipments / refunds )

    So you need to change the calculation process from using the invoiced amount to use the TOTALS only even before invoice With small changes you can achieve what you want without mistakes Code below

    Change the lines ( 390 and below to be like the following ):

    $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 simple answer the solution is not changed the Way of calculation, But the solution change the Default values of the calculations

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

    0 讨论(0)
提交回复
热议问题