1

I want to get all refund items of an order only. I am using below code for this:

$order_id = "100001451";

$creditMemos = Mage::getResourceModel('sales/order_creditmemo_collection');
$creditMemos->addFieldToFilter('order_id', $order_id);
$creditMemos->setOrder('created_at','DESC');
$creditMemos->load();

foreach ($creditMemos->getAllItems() as $item) {
   //var_dump($creditMemo->getData());
    //echo $ceditMemoGrandTotal = $creditMemo->getGrandTotal();
    echo $item->getId();
    echo $item->getSku();
    echo $item->getPrice();
}   

Please help how to get refund items of an order.

1 Answer 1

2

Method 1:

If you have order increment id then you will get the creditmemo items by following code:

$orderIncrementId = '200000604';
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);

if ($order->hasCreditmemos()) {
    foreach ($order->getCreditmemosCollection() as $creditmemo) {
        echo $creditmemo_id = $creditmemo->getId();
        $creditMemo = Mage::getModel('sales/order_creditmemo')->load($creditmemo_id);
        foreach($creditMemo->getAllItems() as $item){
            echo $item->getId();
            echo $item->getSku();
            echo $item->getName();
        }
    }
}

Method 2:

If you have order id then you will get the creditmemo items by following code:

$orderId = '5';
$order = Mage::getModel('sales/order')->load($orderId);

if ($order->hasCreditmemos()) {
    foreach ($order->getCreditmemosCollection() as $creditmemo) {
        echo $creditmemo_id = $creditmemo->getId();
        $creditMemo = Mage::getModel('sales/order_creditmemo')->load($creditmemo_id);
        foreach($creditMemo->getAllItems() as $item){
            echo $item->getId();
            echo $item->getSku();
            echo $item->getName();
        }
    }
}
1
  • What if you don't want to have to specify the orer number? What if you just want the n latest refunds by timestamp? Or just want refunds in general
    – ahnbizcad
    Commented Aug 8, 2018 at 22:18

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.