我如何使用集合以Magento方式运行该SQL?(How would I run that SQL in Magento way using collections?)

编程入门 行业动态 更新时间:2024-10-15 04:19:56
如何使用集合以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)');

更多推荐

本文发布于:2023-08-03 20:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1398898.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   方式   Magento   collections   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!