繁体   English   中英

我如何使用集合以Magento方式运行该SQL?

[英]How would I run that SQL in Magento way using collections?

这是我的SQL:

select created_at from sales_flat_order where created_at > SUBDATE(CURRENT_TIMESTAMP, INTERVAL 3 HOUR); 

这是最近3个小时的订单给我。 现在,如何使用Magento集合运行该查询?

这是我到目前为止的内容:

$orderCollection = Mage::getModel('sales/order')->getCollection();

现在我需要添加一些过滤器,但是我被卡在那里。 感谢您的帮助!

看看@ 在Magento中使用收藏集

$orderCollection = Mage::getModel('sales/order')->getCollection();
$orderCollection->addAttributeToFilter('created_at', array(
    'gt' => new Zend_Db_Expr('SUBDATE(CURRENT_TIMESTAMP, INTERVAL 3 HOUR)'))

要么

$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();

让我知道您是否有任何疑问

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM