How to change order status when refund in magento?

Neeraj Garg picture Neeraj Garg · Apr 30, 2014 · Viewed 10k times · Source

I am working on Magento 1.7 version. I placed a order and make payment using Paypal and refund the amount offline. Order status changed following:-

  1. Pending Payment
  2. Invoice #100000001 created
  3. Processing (IPN "Completed".Registered notification about captured amount of £1. Transaction ID: "0CT123456789874521". )
  4. Processing (Notified customer about invoice #100000001. )
  5. Credit memo #100000001 created
  6. Processing (Refunded amount of £1 offline. )
  7. Processing (IPN "Refunded". Note: Maximum amount available to refund is £0.00 )
  8. Processing (Test order has been refunded.)

Order Status is still showing processing but it should be completed.

Answer

Cristian Quiroz picture Cristian Quiroz · May 5, 2014

In Magento, an order is only marked as Complete once you create an invoice and shipment for it. When you create a credit memo for an order, it instead would be marked as Closed.

If you try to set an order as complete or closed directly using the setStatus method, you will get an exception: The Order State "complete" must not be set manually. Again, these states should be set automatically by Magento.

That being said, if you really want to set these manually, you can get around it like so:

$order->setData('state', 'complete');
$order->setStatus('complete');
$history = $order->addStatusHistoryComment('Manually set order to Complete.', false);
$history->setIsCustomerNotified(false);
$order->save();

You can have a look at this stackoverflow thread for some more info.