SQL Magento 销售报告

标签 sql magento

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

在 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->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 的变量,我无法显示它。 其他变量来自表 sales/order 并且显示良好。

我认为有什么地方不对或遗漏了

            $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 是适当的格式

如果你能帮助我。 谢谢

最佳答案

您没有从联接表中返回任何列。

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

这是要返回的列数组。

关于SQL Magento 销售报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3293589/

相关文章:

jquery - 隐藏的 div 没有显示在所有方面的悬停 Jquery

Magento 引起的 PHP fatal error

javascript - 向 magento 后端注入(inject)新的简单 javascript(作为模块)

magento - "update"元素在 Magento 布局 XML 中有什么作用?

Magento - 在 vi​​ew.phtml 中获取某个类别的项目总数

SQL GROUP BY 返回单行

SQL UPDATE WHERE IN(列表)还是单独更新每个?

sql - 具有不同值的查询执行不同

mysql - 转向 SQL Access

php - 为每个用户运行查询时如何将导入的用户计数到数据库中