【问题标题】:Add total cost field in sales order report magento在销售订单报告 magento 中添加总成本字段
【发布时间】:2014-11-13 14:03:52
【问题描述】:

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

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

【问题讨论】:

    标签: magento


    【解决方案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.
    

    【讨论】:

    • 您好,我尝试和您做同样的事情,但我的 Costo 专栏总是收到 $0,我已按照您的步骤进行操作,但有什么想法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多