How to change order status when returning to magento?

I am working on version Magento 1.7. I placed an order and made a payment using Paypal and returned the amount offline. The order status has changed as follows: -

  • Pending payment
  • Invoice Created # 100000001
  • Processing (IPN β€œCompleted.” Registered Notification of Captured Amount Β£ 1. Transaction ID: β€œ0CT123456789874521”.)
  • Processing (Notified Customer Invoice # 100000001.)
  • Created Credit Memo # 100000001
  • Processing (returns an amount of Β£ 1 offline.)
  • Processing (IPN "Refunded". Note: the maximum amount for a refund is 0.00 rubles.)
  • Processing (fulfillment order has been returned.)

The order status still shows processing, but it must be completed.

+7
magento paypal paypal-ipn
source share
4 answers

Magento will mark the order as complete once you create an invoice and dispatch for it. When you create a credit memo for an order, it will instead be marked Closed.

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

However, if you really want to install them manually, you can work around it like this:

 $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 https://stackoverflow.com/a/166777/ for more information.

+5
source share

Take a look at Mage_Sales_Model_Order_Payment::refund() , where return processing is:

  $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, $message); Mage::dispatchEvent('sales_order_payment_refund', array('payment' => $this, 'creditmemo' => $creditmemo)); 

After the order status has been configured for processing, event sales_order_payment_refund . You can write an observer who is listening to this event. If the payment method was PayPal, you can update the status of the order, as described in the answer of Christian Kiroz.

+2
source share

I am studying this problem and it seems to be a rounding problem. After creating a credit memo, the order status should be closed, but in my case, some returned orders retained their original status.

When creating a credit memo, two functions Mage_Sales_Model_Order::canCreditmemo() and Mage_Sales_Model_Order_Invoice::canRefund() called. They both return false if the difference between the total amount and the recoverable amount is less than 0.0001.

In my testing, this was not the case for some returned orders, regardless of the payment method used. Increasing the value to 0.001 in both functions led to a closed order status. This also explains why only some orders retain their status, and some close correctly depending on the price and amount of tax.

I solved the problem by overriding the main Magento classes in local and replacing the following lines as follows:

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 a while to track down this error.

+2
source share

in the application \ code \ core \ Mage \ Payment \ Model \ Method \ Abstract.php

you can set the order status as completed

 public function processBeforeRefund($invoice, $payment) { // Add your code to set order as complete $payment->setRefundTransactionId($invoice->getTransactionId()); return $this; } 

Hope this helps.

+1
source share

All Articles