gpt4 book ai didi

SQL Magento 销售报告

转载 作者:行者123 更新时间:2023-12-05 01:37:25 26 4
gpt4 key购买 nike

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

在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com