1

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?

1

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.

2
  • Hello @Ashvin Monpara, I don't understand your answer. Can you please explain more? Mar 12 '16 at 13:15
  • Order status/state Closed/closed is a "protected" status/state, which cannot be changed, along with Complete/complete. This means when you use the method setState, it will not work. This is because in order to have a Closed order, you must have a fully invoiced and shipped order fully refunded. It looks like in your case you don't have a full shipment. If you have a full shipment and still not getting to Closed, something was done wrong. Mar 12 '16 at 13:38
1

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

From :

...
if (0 == $this->getBaseGrandTotal() || $this->canCreditmemo()) {
    if ($this->getState() !== self::STATE_COMPLETE) {
        $this->_setState(self::STATE_COMPLETE, true, '', $userNotification);
    }
}           
/**
 * Order can be closed just in case when we have refunded amount.
 * In case of "0" grand total order checking ForcedCanCreditmemo flag
 */
elseif (floatval($this->getTotalRefunded()) || (!$this->getTotalRefunded() && $this->hasForcedCanCreditmemo()))
{
    if ($this->getState() !== self::STATE_CLOSED) {
        $this->_setState(self::STATE_CLOSED, true, '', $userNotification);
    }
}
...

To :

...
if ($this->canCreditmemo()) {                                                           // custom code
    if ($this->getState() !== self::STATE_COMPLETE) {
        $this->_setState(self::STATE_COMPLETE, true, '', $userNotification);
    }
}           
/**
 * Order can be closed just in case when we have refunded amount.
 * In case of "0" grand total order checking ForcedCanCreditmemo flag
 */
elseif (floatval($this->getTotalRefunded()) || (!$this->getTotalRefunded() && $this->hasForcedCanCreditmemo()))
{
    if ($this->getState() !== self::STATE_CLOSED) {
        $this->_setState(self::STATE_CLOSED, true, '', $userNotification);
    }
}
elseif(abs($this->getStore()->roundPrice($this->getGrandTotal())) == 0 && $this->getDiscountRefunded() == $this->getDiscountAmount())
{
    if ($this->getState() !== self::STATE_CLOSED) {
        $this->_setState(self::STATE_CLOSED, true, '', $userNotification);
    }
}
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.