我正在尝试获取过去 24 小时内的所有订单商品。我已锁定查询,因此它返回了我需要的内容(order_id 和created_on 值)。
$order_items = Mage::getResourceModel('sales/order_item_collection')
->addAttributeToSelect('order_id')
->addAttributeToSelect('created_at')
->addFieldToFilter('sku', $membership_sku)
->toArray();
我已经搜索遍了,看起来我需要添加另一个 ->addFieldToFilter() 属性,但我不太确定它应该如何构造。任何例子都会非常有帮助。
如果有帮助,我正在使用 Magento Enterprise v1.12.0.2
最佳答案
我认为你需要重新安排你的时间才能获得好的结果:
$time = time();
$to = date('Y-m-d H:i:s', $time);
$lastTime = $time - 86400; // 60*60*24
$from = date('Y-m-d H:i:s', $lastTime);
$order_items = Mage::getResourceModel('sales/order_item_collection')
->addAttributeToSelect('order_id')
->addAttributeToSelect('created_at')
->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to))
->load();
关于magento - 在 Magento 中获取过去 24 小时内的订单商品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14151134/