2

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?

2 Answers 2

2

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()
0
0

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
  } 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.