2010-07-20 170 views
3

我试图在报告/销售/运输中添加新列。列现在可以,但我无法显示来自其他表的值。SQL Magento销售报告

在app /代码

/本地/法师/销售/型号/ Mysql4 /报告/ Shipping.php

protected function _aggregateByOrderCreatedAt($from, $to) 
{ 
    try { 
     $tableName = $this->getTable('sales/shipping_aggregated_order'); 
     $writeAdapter = $this->_getWriteAdapter(); 

     $writeAdapter->beginTransaction(); 

     if (is_null($from) && is_null($to)) { 
      $writeAdapter->query("TRUNCATE TABLE {$tableName}"); 
     } else { 
      $where = (!is_null($from)) ? "so.updated_at >= '{$from}'" : ''; 
      if (!is_null($to)) { 
       $where .= (!empty($where)) ? " AND so.updated_at <= '{$to}'" : "so.updated_at <= '{$to}'"; 
      } 

      $subQuery = $writeAdapter->select(); 
      $subQuery->from(array('so'=>$this->getTable('sales/order')), array('DISTINCT DATE(so.created_at)')) 
       ->where($where); 

我加这4条线:$ subQuery-> joinInner:

  $subQuery->joinInner(array('sd'=> $this->getTable('sales/order_datetime')), 
      "`sd`.`entity_id` = `so`.`entity_id`", 
      array() 
     ); 


      $deleteCondition = 'DATE(period) IN (' . new Zend_Db_Expr($subQuery) . ')'; 
      $writeAdapter->delete($tableName, $deleteCondition); 
     } 


     $columns = array(
      'period'    => "DATE(created_at)", 
      'shipping_description' => 'shipping_description', 
      'orders_count'   => 'COUNT(entity_id)', 
      'total_shipping'  => 'SUM(`base_shipping_amount` * `base_to_global_rate`)', 

      'store_id'    => 'store_id', 
      'order_status'   => 'status', 
      'point_relais'    => 'shipping_description', 
      'date_commande'    => "DATE(created_at)", 
      'date_livraison'    => "DATE(value)" 

     $select = $writeAdapter->select() 
      ->from($this->getTable('sales/order'), $columns) 
      ->where('state NOT IN (?)', array(
       Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, 
       Mage_Sales_Model_Order::STATE_NEW 
      )) 
      ->where('is_virtual = 0'); 

      if (!is_null($from) || !is_null($to)) { 
       $select->where("DATE(created_at) IN(?)", new Zend_Db_Expr($subQuery)); 
      } 

      $select->group(array(
       "DATE(created_at)", 
       'store_id', 
       'order_status', 
       'shipping_description' 
       'point_relais', 
       'date_commande', 
       'date_livraison', 
       'client' 
      )); 

最后,'date_livraison'中的“value”是来自表sales/order_datetime的唯一变量,我无法显示它。 其他变量来自表销售/订单,并且很好地显示。

我觉得有什么不对或缺失

  $subQuery->joinInner(array('sd'=> $this->getTable('sales/order_datetime')), 
      "`sd`.`entity_id` = `so`.`entity_id`", 
      array() 
     ); 

我已经声明在应用程序/代码表sales_order_datetime /核心/法师/销售/等/ config.xml中有:

   <order_datetime><table>sales_order_datetime</table></order_datetime> 

并在数据库中date_livraison是在适当的格式

如果你能帮助我。 谢谢

回答

0

您没有返回连接表中的任何列。

$subQuery->joinInner(array('sd'=> $this->getTable('sales/order_datetime')), 
     "`sd`.`entity_id` = `so`.`entity_id`", 
     array('name_of_column') // <---This is what is missing. 
    ); 

这是要返回的列数组。