在销售订单报告magento中添加总成本字段

时间:2014-11-13 14:03:52

标签: magento

我试图在销售订单报告中获得总成本,但没有成功。我可以在" sales_order_aggregated_created"中看到相关数据。和" sales_order_aggregated_updated"数据库中的表但无法查看订单的总成本。数据通过app / code / core / Mage / Sales / Model / Resource / Order / collection.php进行管理

如果有人想要获得相同的价值,请提供帮助。

1 个答案:

答案 0 :(得分:1)

Finally I have done with the same. I have made corrections in three files to get the total cost field in sales order report. First of all copy this three core files to local folder.

1.Add total cost app/code/local/Mage/Sales/Model/Resource/Report/Order/Createdat.php in columns array around line number 95
'total_base_cost'                => new Zend_Db_Expr('SUM(oi.total_base_cost)')

Dont forget to add same column (total_base_cost) in sales_order_aggregated_created table in databse. Now the $columns would be as below:

 $columns = array(
                // convert dates from UTC to current admin timezone
                'period'                         => $periodExpr,
                'store_id'                       => 'o.store_id',
                'order_status'                   => 'o.status',
                'orders_count'                   => new Zend_Db_Expr('COUNT(o.entity_id)'),
                'total_qty_ordered'              => new Zend_Db_Expr('SUM(oi.total_qty_ordered)'),
                'total_base_cost'                => new Zend_Db_Expr('SUM(oi.total_base_cost)'),
                'total_qty_invoiced'             => new Zend_Db_Expr('SUM(oi.total_qty_invoiced)'),
                'total_income_amount'            => new Zend_Db_Expr(
                    sprintf('SUM((%s - %s) * %s)',
                        $adapter->getIfNullSql('o.base_grand_total', 0),
                        $adapter->getIfNullSql('o.base_total_canceled',0),
                        $adapter->getIfNullSql('o.base_to_global_rate',0)
                    )
                ),
 and add same column in $cols array to get the value from sales/order_item table around line number 204
  'total_base_cost'  => new Zend_Db_Expr('SUM(base_cost)')
 now $cols array is:
 $cols            = array(
                'order_id'           => 'order_id',
                'total_qty_ordered'  => new Zend_Db_Expr("SUM(qty_ordered -  {$qtyCanceledExpr})"),
                'total_base_cost'  => new Zend_Db_Expr('SUM(base_cost)'),
                'total_qty_invoiced' => new Zend_Db_Expr('SUM(qty_invoiced)'),
            );

2. Add same column in app/code/local/Mage/Sales/Model/Resource/Report/Order/Collection.php arround line 87
'total_base_cost'                => 'SUM(total_base_cost)',
now $this->_selected array will be as below:
$this->_selectedColumns = array(
                'period'                         => $this->_periodFormat,
                'orders_count'                   => 'SUM(orders_count)',
                'total_qty_ordered'              => 'SUM(total_qty_ordered)',
                'total_base_cost'                => 'SUM(total_base_cost)',
                'total_qty_invoiced'             => 'SUM(total_qty_invoiced)',
                'total_income_amount'            => 'SUM(total_income_amount)',
                'total_revenue_amount'           => 'SUM(total_revenue_amount)',
                'total_profit_amount'            => 'SUM(total_profit_amount)',
                'total_invoiced_amount'          => 'SUM(total_invoiced_amount)',
                'total_canceled_amount'          => 'SUM(total_canceled_amount)',
                'total_paid_amount'              => 'SUM(total_paid_amount)',
                'total_refunded_amount'          => 'SUM(total_refunded_amount)',
                'total_tax_amount'               => 'SUM(total_tax_amount)',
                'total_tax_amount_actual'        => 'SUM(total_tax_amount_actual)',
                'total_shipping_amount'          => 'SUM(total_shipping_amount)',
                'total_shipping_amount_actual'   => 'SUM(total_shipping_amount_actual)',
                'total_discount_amount'          => 'SUM(total_discount_amount)',
                'total_discount_amount_actual'   => 'SUM(total_discount_amount_actual)',
            );
3. Final display the column in sales order report grid by adding the same column in the file app/code/local/Mage/Adminhtml/Block/Report/Sales/Sales/Grid.php

$this->addColumn('total_base_cost', array(
            'header'        => Mage::helper('sales')->__('Cost'),
            'type'          => 'currency',
            'currency_code' => $currencyCode,
            'index'         => 'total_base_cost',
            'total'         => 'sum',
            'sortable'      => false,
            'rate'          => $rate,
        ));

It may help someone else who wants to add the same column.
相关问题