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:-
Order Status is still showing processing but it should be completed.
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.
I've been investigating this issue and it seems that it is actually a rounding problem. After creating a credit memo the order status should be closed but in my case also some refunded orders kept their original status.
When creating a credit memo two functions Mage_Sales_Model_Order::canCreditmemo()
and Mage_Sales_Model_Order_Invoice::canRefund()
are called. They both return false if the difference between grand total and refunded amount is less than 0.0001.
In my testing this wasn't the case for some refunded orders irrespective to the used payment method. Increasing the value to 0.001 in both functions resulted in a closed order status. This also explains why only some orders kept their state and some are closed correctly depending on price and tax amount.
I solved the issue by overriding both Magento core classes in local and replaced the following lines with this:
Mage_Sales_Model_Order:
if (abs($this->getStore()->roundPrice($this->getTotalPaid()) - $this->getTotalRefunded()) < .001) {
return false;
}
Mage_Sales_Model_Order_Invoice:
if (abs($this->getBaseGrandTotal() - $this->getBaseTotalRefunded()) < .001) {
return false;
}
I hope this helps others because it took me some time to trace down that bug.
Have a look at Mage_Sales_Model_Order_Payment::refund()
where the refund is processed:
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, $message);
Mage::dispatchEvent('sales_order_payment_refund', array('payment' => $this, 'creditmemo' => $creditmemo));
After the order state was set to processing the event sales_order_payment_refund
is dispatched. You could write an observer which listens to this event. If the payment method was PayPal you could update the order state as described in the answer by Cristian Quiroz.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With