Thursday, December 4, 2014

How to Un-Cancel Magento order

Hi,
I know that there is possibility that we could find some articles on the internet with this thematic, but let me add my own version.
Let’s first say that programmatic Un-Canceling orders should not be the best way to resolve issues with order cancelled by mistake.


I would recommend to re-create order from admin instead (if possible). But there are some specific situations in which we really need to do this, so let’s get to the code:
 
  //...
         
  $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
 
  $order->setSubtotalCanceled(null);
  $order->setBaseSubtotalCanceled(null);
 
  $order->setTaxCanceled(null);
  $order->setBaseTaxCanceled(null);
 
  $order->setShippingCanceled(null);
  $order->setBaseShippingCanceled(null);
 
  $order->setDiscountCanceled(null);
  $order->setBaseDiscountCanceled(null);
 
  $order->setTotalCanceled(null);
  $order->setBaseTotalCanceled(null);
 
  $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, 
                  'pending_payment', 'This order is uncanceled by Admin!');
 
  $order->setStatus(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
  $order->save(); 
 
  //Don't forget to un-cancel order items ...
  foreach ($order->getAllItems() as $item) {
     $item->setQtyCanceled(0);
     $item->save();
  }       
   
  //...
That’s it for now. I hope that this small tip will be useful

,

1 comment:

  1. More complex than I thought! Thanks for posting this.

    ReplyDelete