2014-11-13 7 views
1

Я попытался получить общую стоимость в отчете о заказе, но безуспешно. Я вижу связанные данные в таблицах «sales_order_aggregated_created» и «sales_order_aggregated_updated» в базе данных, но не могу видеть общую стоимость заказов. Управление данными осуществляется через приложение/код/​​ядро ​​/ 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. 
+0

Привет, я попытался сделать то же самое, что и вы, но я получаю всегда $ 0 в столбце Costo, я выполнил ваши шаги, но получил это, любые идеи? – lucasvm1980

Смежные вопросы