SQL Magento销售报告

时间:2010-07-20 19:26:19

标签: sql magento report sales

我正在尝试在报告/销售/运输中添加新列。列现在可以,但我无法显示来自另一个表的值。

在app / code / local / Mage / Sales / Model / Mysql4 / Report / 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-&gt; 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”是来自table sales / order_datetime的唯一变量,我无法显示它。 其他变量来自表销售/订单,并且显示良好。

我认为

中存在错误或缺失
            $subQuery->joinInner(array('sd'=> $this->getTable('sales/order_datetime')), 
            "`sd`.`entity_id` = `so`.`entity_id`",
            array()
        );

我在app / code / Core / Mage / Sales / etc / config.xml中声明了表sales_order_datetime:

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

在数据库中,date_livraison采用适当的格式

如果你能帮助我。 感谢

1 个答案:

答案 0 :(得分: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.
    );

这是要返回的列数组。