[英]How would I run that SQL in Magento way using collections?
This is my SQL: 这是我的SQL:
select created_at from sales_flat_order where created_at > SUBDATE(CURRENT_TIMESTAMP, INTERVAL 3 HOUR);
This is returning me the orders from the last 3 hours. 这是最近3个小时的订单给我。 Now, how would I run that query using Magento collection?
现在,如何使用Magento集合运行该查询?
This is what I have so far: 这是我到目前为止的内容:
$orderCollection = Mage::getModel('sales/order')->getCollection();
Now I need to add some filter, but I am stuck there. 现在我需要添加一些过滤器,但是我被卡在那里。 Thanks for helping!
感谢您的帮助!
Take a look @ Using Collections in Magento 看看@ 在Magento中使用收藏集
$orderCollection = Mage::getModel('sales/order')->getCollection();
$orderCollection->addAttributeToFilter('created_at', array(
'gt' => new Zend_Db_Expr('SUBDATE(CURRENT_TIMESTAMP, INTERVAL 3 HOUR)'))
or 要么
$orderCollection = Mage::getModel('sales/order')->getCollection();
$orderCollection->getSelect()->where('created_at > SUBDATE(CURRENT_TIMESTAMP, INTERVAL 3 HOUR)');
$time = time();
$to = date('Y-m-d H:i:s', $time);
$lastTime = $time - 10800; // 3hr(60min/hr)(60sec/min)
$from = date('Y-m-d H:i:s', $lastTime);
$order =Mage::getModel('sales/order')->getCollection();
->addAttributeToSelect('*')
->addAttributeToSelect('created_at')
->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to))
->load();
Let me know if you have any query 让我知道您是否有任何疑问
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.