0

I'm new to Magento2 API, I'm trying to retrieve credit memo based on order ID, but it seems to fail to retrieve. Any ideas how to get the credit memo data?

$credit_memo = $orderCollection->getCreditmemosCollection();

foreach ($credit_memo->getAllItems() as $item) {
    $result['items'] = $item->getData();
}
print_r($result);die();

1 Answer 1

1

I assume that $orderCollection is a collection of orders and not an order.
in this case you need to loop through it and retrieve the credit memos for each order.

foreach ($orderCollection as $order) {
{
    $creditMemos = $order->getCreditmemosCollection();
    foreach ($creditMemos as $creditMemo) { //go through all the credit memos for the current order.
        //do something with $creditMemo here
        foreach ($creditMemos->getAllItems() as $item) { //get all credit memo items if needed
            //do something with $item.
        }
    }
}

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.