I'm attempting to get all order items from the last 24 hours. I have the query locked down, so it's giving me back what I need (an order_id, and created_on value).
$order_items = Mage::getResourceModel('sales/order_item_collection')
->addAttributeToSelect('order_id')
->addAttributeToSelect('created_at')
->addFieldToFilter('sku', $membership_sku)
->toArray();
I've searched all over, and it looks like I need to add another ->addFieldToFilter() property, but I'm not quite sure how it should be structured. Any examples would be extremely helpful.
If it helps, I'm using Magento Enterprise v1.12.0.2
After some additional research, I came across the documentation here. I decided to use strtotime since it's easier, however if someone else has a better solution, please let me know.
->addFieldToFilter('created_at', array(
'from' => strtotime('-1 day', time()),
'to' => time(),
'datetime' => true
))
I think you will need to reformat your times to be able to get good results:
$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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With