1

在以前版本的 Magento(CE 为 1.6 及之前版本,EE 为 1.11 及之前版本)中,管理仪表板上的图表将反映所接受的总订单数。自 1.7/1.12 起,这已更改为反映已开票的订单。我们使用自定义状态,并且喜欢将仪表板图表作为关于销售的快速心跳类型报告。但是,由于我们处理后端订单处理的方式(不是通过 Magento),我们的订单都没有达到发票状态

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

4

3 回答 3

3

Oleg Ishenko 的回答为您指明了正确的方向,但并不全面。
1.在您创建的模块中,您需要覆盖Mage_Reports_Model_Resource_Order_Collection:所以在您的config.xml放置中:

...
    <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个方法:

<?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;
    }

}

在这个例子中,我已经注释了按订单状态进行的过滤,但是您可以轻松地取消它并放置您不想计入的订单状态。

高温高压

于 2013-01-25T08:17:05.367 回答
1

我做了一些挖掘,看起来这个集合正在内置Mage_Reports_Model_Resource_Order_Collection::_prepareSummaryLive()。在 Magento 1.7.0.2 中,限制基于订单,这些订单不在 statiMage_Sales_Model_Order::STATE_PENDING_PAYMENTMage_Sales_Model_Order::STATE_NEW.

无论如何,可以在这里操作集合过滤器(另见 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);

当然,任何提议的操作都是类重写:)

于 2013-01-24T17:45:09.183 回答
0

我找到了一种建议的解决方案,但应用它并没有取得多大成功。如果其他人可以验证这是一个可能的解决方案,我将修改此答案以反映这一点。我还将更改答案以正确应用更改而不修改核心文件。


打开 /app/code/core/Mage/Adminhtml/Block/Dashboard/Orders/Grid.php 并添加

$collection->addAttributeToFilter('state', Mage_Sales_Model_Order::STATE_PROCESSING);

$collection = Mage::getResourceModel('reports/order_collection')
            ->addItemCountExpr()
            ->joinCustomerName('customer')
            ->orderByCreatedAt();
于 2013-01-18T15:51:12.170 回答