在Magento的1.7/1.12版中更改仪表板图 [英] Change the Dashboard Graph in version 1.7/1.12 of Magento

查看:63
本文介绍了在Magento的1.7/1.12版中更改仪表板图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Magento的早期版本中(对于CE,为1.6或更低版本;对于EE,为1.11以及更低版本),管理控制台上的图表将反映已接受的总订单数.从1.7/1.12开始,现在已对其进行更改以反映已开具发票的订单.我们使用自定义状态,就像将仪表板"图用作销售的快速心跳类型报告一样.但是,由于我们处理后端订单的方式(不是通过Magento),因此我们的订单都无法达到发票状态

In previous versions of Magento (1.6 and before for CE, 1.11 and before for EE) the graph on the admin Dashboard would reflect the count of total orders taken. Since 1.7/1.12 this has now been changed to reflect orders that have been invoiced. We use custom statuses and like having the Dashboard graph as a quick heart beat type report on sales. However, none of our orders ever reach an invoiced status because of how we handle back end order processing (not through Magento)

如何更改仪表板图以报告订单的处理中",已开具发票"以及我们的自定义状态?我们的自定义状态与处理中"相关,因此我可能只需要查询处理中"和已开具发票"即可.根据Magento支持,这种修改是可能的,但是除了/app/design/Adminhtml/default/default/template/dashboard/graph.phtml文件之外,我不确定从哪里开始寻找.谢谢!

How can I change the dashboard graph to report on Processing, Invoiced, and our custom status for an order? Our custom status has been tied to Processing so I may only need to query for Processing and Invoiced. According to Magento Support this kind of modification is possible but I am not sure where to start looking besides the /app/design/Adminhtml/default/default/template/dashboard/graph.phtml file. Thanks!

推荐答案

奥列格·伊先科(Oleg Ishenko)的回答指出了正确的方向,但并不全面.
1.在您创建的模块中,您需要覆盖Mage_Reports_Model_Resource_Order_Collection :,因此在您的config.xml位置中:

The answer from Oleg Ishenko points you in the right direction, but is not quite comprehensive.
1. In the module you create, you need to override Mage_Reports_Model_Resource_Order_Collection: so in your 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.然后创建类(尊重路径),在该类中,您需要重写2个方法:

2.Then create the 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 have comented the filtering by order's status, but you can easily uncoment it and put the order statuses you don't want to be counted in.

HTH

这篇关于在Magento的1.7/1.12版中更改仪表板图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆