在Magento的早期版本(1.6和之前的CE,1.11和之前EE)的管理仪表板图表会反映出拍摄总订单数。 由于1.7 / 1.12这个现在已经改变,以反映已开具发票的订单。 我们使用自定义的状态和喜欢具有面板图形上销售的快速心脏跳动类型的报告。 然而,没有我们的订单有史以来达到,因为我们如何处理后端的订单处理(而不是通过Magento的)的发票状态
如何更改仪表板图形上处理,发票,我们的自定义状态报告的订单? 我们的自定义状态已被捆绑处理,所以我可能只需要查询处理和开具发票。 根据Magento的支持这种修改是可能的,但我不知道从哪里开始寻找除了/app/design/Adminhtml/default/default/template/dashboard/graph.phtml文件。 谢谢!
从奥列格Ishenko答案要点,你在正确的方向,但并不是相当全面。
1.在您所创建的模块,你需要重写Mage_Reports_Model_Resource_Order_Collection
:所以在你config.xml
放:
...
<global>
<models>
<yourmodule>
<class>Namespace_Yourmodule_Model</class>
</yourmodule>
<reports_resource>
<rewrite>
<order_collection>Namespace_Yourmodule_Model_Reports_Resource_Order_Collection</order_collection>
</rewrite>
</reports_resource>
</models>
</global>
...
2.然后创建一个类(尊重的路径),并在这个类,你需要重写2种方法:
<?php
/**
* Show all orders, not only the invoiced one
*/
class Namespace_Yourmodule_Model_Reports_Resource_Order_Collection extends Mage_Reports_Model_Resource_Order_Collection
{
protected function _prepareSummaryLive($range, $customStart, $customEnd, $isFilter = 0)
{
$this->setMainTable('sales/order');
$adapter = $this->getConnection();
/**
* Reset all columns, because result will group only by 'created_at' field
*/
$this->getSelect()->reset(Zend_Db_Select::COLUMNS);
$expression = sprintf('%s - %s - %s - (%s - %s - %s)',
$adapter->getIfNullSql('main_table.base_total_invoiced', 0),
$adapter->getIfNullSql('main_table.base_tax_invoiced', 0),
$adapter->getIfNullSql('main_table.base_shipping_invoiced', 0),
$adapter->getIfNullSql('main_table.base_total_refunded', 0),
$adapter->getIfNullSql('main_table.base_tax_refunded', 0),
$adapter->getIfNullSql('main_table.base_shipping_refunded', 0)
);
if ($isFilter == 0) {
$this->getSelect()->columns(array(
'revenue' => new Zend_Db_Expr(
sprintf('SUM((%s) * %s)', $expression,
$adapter->getIfNullSql('main_table.base_to_global_rate', 0)
)
)
));
} else {
$this->getSelect()->columns(array(
'revenue' => new Zend_Db_Expr(sprintf('SUM(%s)', $expression))
));
}
$dateRange = $this->getDateRange($range, $customStart, $customEnd);
$tzRangeOffsetExpression = $this->_getTZRangeOffsetExpression(
$range, 'created_at', $dateRange['from'], $dateRange['to']
);
$this->getSelect()
->columns(array(
'quantity' => 'COUNT(main_table.entity_id)',
'range' => $tzRangeOffsetExpression,
))
//BOF modification
// ->where('main_table.state NOT IN (?)', array(
// Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
// Mage_Sales_Model_Order::STATE_NEW)
// )
//EOF modification
->order('range', Zend_Db_Select::SQL_ASC)
->group($tzRangeOffsetExpression);
$this->addFieldToFilter('created_at', $dateRange);
return $this;
}
protected function _calculateTotalsLive($isFilter = 0)
{
$this->setMainTable('sales/order');
$this->removeAllFieldsFromSelect();
$adapter = $this->getConnection();
$baseTotalInvoiced = $adapter->getIfNullSql('main_table.base_grand_total', 0);
$baseTotalRefunded = $adapter->getIfNullSql('main_table.base_discount_refunded', 0);
$baseTaxInvoiced = $adapter->getIfNullSql('main_table.base_tax_amount', 0);
$baseTaxRefunded = $adapter->getIfNullSql('main_table.base_tax_refunded', 0);
$baseShippingInvoiced = $adapter->getIfNullSql('main_table.base_shipping_amount', 0);
$baseShippingRefunded = $adapter->getIfNullSql('main_table.base_shipping_refunded', 0);
$revenueExp = sprintf('%s - %s - %s - (%s - %s - %s)',
$baseTotalInvoiced,
$baseTaxInvoiced,
$baseShippingInvoiced,
$baseTotalRefunded,
$baseTaxRefunded,
$baseShippingRefunded
);
$taxExp = sprintf('%s - %s', $baseTaxInvoiced, $baseTaxRefunded);
$shippingExp = sprintf('%s - %s', $baseShippingInvoiced, $baseShippingRefunded);
if ($isFilter == 0) {
$rateExp = $adapter->getIfNullSql('main_table.base_to_global_rate', 0);
$this->getSelect()->columns(
array(
'revenue' => new Zend_Db_Expr(sprintf('SUM((%s) * %s)', $revenueExp, $rateExp)),
'tax' => new Zend_Db_Expr(sprintf('SUM((%s) * %s)', $taxExp, $rateExp)),
'shipping' => new Zend_Db_Expr(sprintf('SUM((%s) * %s)', $shippingExp, $rateExp))
)
);
} else {
$this->getSelect()->columns(
array(
'revenue' => new Zend_Db_Expr(sprintf('SUM(%s)', $revenueExp)),
'tax' => new Zend_Db_Expr(sprintf('SUM(%s)', $taxExp)),
'shipping' => new Zend_Db_Expr(sprintf('SUM(%s)', $shippingExp))
)
);
}
$this->getSelect()->columns(array(
'quantity' => 'COUNT(main_table.entity_id)'
));
//BOF modification
// ->where('main_table.state NOT IN (?)', array(
// Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
// Mage_Sales_Model_Order::STATE_NEW)
// );
//EOF modification
return $this;
}
}
在这个例子中,我通过订单的状态comented过滤,但你可以很容易地uncoment,并把该订单状态,你不想被计算在内。
HTH
我做了一些挖掘,它看起来像集合正在兴建Mage_Reports_Model_Resource_Order_Collection::_prepareSummaryLive()
在Magento 1.7.0.2的限制是基于订单,这是不是在为static Mage_Sales_Model_Order::STATE_PENDING_PAYMENT
或Mage_Sales_Model_Order::STATE_NEW
。
总之,收集过滤器可以在这里操作(也看到在github类文件 ):
$this->getSelect()
->columns(array(
'quantity' => 'COUNT(main_table.entity_id)',
'range' => $tzRangeOffsetExpression,
))
->where('main_table.state NOT IN (?)', array(
Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
Mage_Sales_Model_Order::STATE_NEW)
)
->order('range', Zend_Db_Select::SQL_ASC)
->group($tzRangeOffsetExpression);
提出的任何操作,当然是类重写:)
我发现一个提出的解决方案,但我没有将它很成功。 如果有人可以证实这是一个可行的解决方案,我将修改这个答案反映如此。 我也将改变答案正确应用更改,而无需修改核心文件。
打开/app/code/core/Mage/Adminhtml/Block/Dashboard/Orders/Grid.php并添加
$collection->addAttributeToFilter('state', Mage_Sales_Model_Order::STATE_PROCESSING);
后
$collection = Mage::getResourceModel('reports/order_collection')
->addItemCountExpr()
->joinCustomerName('customer')
->orderByCreatedAt();