Magento 1
I'm trying to get some of the latest refunds issued in magento by timestamp. I want to be able to get them WITHOUT specifying any specific order. How do I do this programmatically?
Here's my take:
$creditmemo = Mage::getResourceModel('sales/order_creditmemo_collection')
->setOrder('created_at', 'DESC') // order by timestamp
->setPage(1, 1) // limit to one item for an efficiency query
->getFirstItem(); // or ->getLastItem()
To add to kiatng's answer, including other details as an example.
$current_page = 1;
$page_size = 100;
$creditmemos_collection = Mage::getResourceModel('sales/order_creditmemo_collection')
->addAttributeToSort('created_at', 'DESC') // order by timestamp
->setPage($current_page, $page_size)
;
foreach ($creditmemos_collection as $creditmemo) {
$creditmemo->getBaseAdjustmentPositive();
// and other properties
$order = $creditmemo->getOrder();
$order->getIncrementId();
// and other properties
$items_collection = $creditmemo->getItemsCollection();
foreach ($items_collection as $item) {
$item->getSku();
// and other properties
}
}