我如何使用集合以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();现在我需要添加一些过滤器,但我被困在那里。 谢谢你的帮助!
This is my 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. Now, how would I run that query using Magento collection?
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!
最满意答案
看看在Magento中使用Collections
$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)');Take a look @ Using Collections in 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)');更多推荐
发布评论