Sql 如何通过Magento中的集合获取整个期间的所有订单?
我需要检索一段时间内接收的所有订单的集合 我还需要查询每天的订单数量 以下是我尝试过的:Sql 如何通过Magento中的集合获取整个期间的所有订单?,sql,magento,collections,Sql,Magento,Collections,我需要检索一段时间内接收的所有订单的集合 我还需要查询每天的订单数量 以下是我尝试过的: $fromDate = '2016-01-15 00:00:00'; $toDate = '2016-02-15 00:00:00'; $orders = Mage::getModel('sales/order')->getCollection() ->addAttributeToSelect('created_at') ->addAttr
$fromDate = '2016-01-15 00:00:00';
$toDate = '2016-02-15 00:00:00';
$orders = Mage::getModel('sales/order')->getCollection()
->addAttributeToSelect('created_at')
->addAttributeToFilter('created_at', array('from'=>$fromDate, 'to'=>$toDate));
$orders->getSelect()
->columns('COUNT(created_at)')
->group('created_at');
像下面这样的东西应该能满足你的需要。就我个人而言,我会从00:00:00跑到23:59:59。请注意,这将基于UTC(因为这是Magento存储时间/日期的方式)。您可能需要将这些时间偏移到存储时区
$fromDate = '2016-03-01 00:00:00';
$toDate = '2016-03-31 23:59:59';
$orders = Mage::getModel('sales/order')->getCollection()
->addAttributeToSelect('created_at')
->addAttributeToFilter('created_at', array('gteq'=>$fromDate))
->addAttributeToFilter('created_at', array('lteq'=>$toDate));
$orders->getSelect()
->columns( 'COUNT(*) AS orders_count' )
->group( 'DATE_FORMAT(created_at, "%d-%m-%y")' );
foreach($orders as $order) {
// logic
}
像下面这样的东西应该能满足你的需要。就我个人而言,我会从00:00:00跑到23:59:59。请注意,这将基于UTC(因为这是Magento存储时间/日期的方式)。您可能需要将这些时间偏移到存储时区
$fromDate = '2016-03-01 00:00:00';
$toDate = '2016-03-31 23:59:59';
$orders = Mage::getModel('sales/order')->getCollection()
->addAttributeToSelect('created_at')
->addAttributeToFilter('created_at', array('gteq'=>$fromDate))
->addAttributeToFilter('created_at', array('lteq'=>$toDate));
$orders->getSelect()
->columns( 'COUNT(*) AS orders_count' )
->group( 'DATE_FORMAT(created_at, "%d-%m-%y")' );
foreach($orders as $order) {
// logic
}
谢谢,伙计,这正是我要找的。谢谢,伙计,这正是我要找的。