Magento 1.9 Order Status – After Credit Memo is Complete for 0.00 Total

creditmemomagento-1.9

There is no creditmemo button showing in magento order with total paid amount is 0 after applying discount.

For this I changed canCreditmemo() function in app/code/local/Mage/Sales/Model/Order.php .

From :

...
if (abs($this->getStore()->roundPrice($this->getTotalPaid()) - $this->getTotalRefunded()) < .0001) {
                return false;
            }
...

To :

...
if (abs($this->getStore()->roundPrice($this->getTotalPaid()) - $this->getTotalRefunded()-$this->getDiscountAmount()) < .0001) {
                return false;
            }
...

After that in order Creditmemo button showing, creditmemo create successfully, product qty also refunded in magento store.

But after create creditmemo of all products then order status should be closed but in this case order status still complete.

How to change order status to closed for that order?

Best Answer

I have managed to get the order status to closed after a refund two step :-

1->//after the refund code. Calling

 $order->save(); 

Preventing the sales_order_invoice_save_after event from firing twice by adding this to the top of my event method:

// prevent this event from firing twice

2:-

 if(Mage::registry('sales_order_invoice_save_after_event_triggered'))
    {
        return $this; // this method has already been executed once in this request
    }
    Mage::register('sales_order_invoice_save_after_event_triggered', true);

try another:- In any case, you have two options.

Do a full shipment (dummy if necessary). Refund fully and you should get to Closed automatically.

Go around the restriction by using

`setData('state', Mage_Sales_Model_Order::STATE_CLOSED)` 

instead of setState.