簡體   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