Theres information missing, however I will answer it using assumptions.
Using a clean install of Magento CE, I attempted to use the code above to recreate a existing complete order. Some of the assumptions I made are:
Existing Completed Order
- One product ordered
- Billing/Shipping address the same
- Payment Method: Check/Money Order
- Shipping Method: Flat rate
For simplicity, I created a file in my root with your code (yours would be in your extension). This file contained:
<?php
include_once 'app/Mage.php';
Mage::app();
$orderId= '1'; //You were missing the Order ID in your code (Issue #1)
$orig_order = Mage::getModel('sales/order')->load((int)$orderId);
$order_model = Mage::getSingleton('adminhtml/sales_order_create');
try {
$orig_order->setReordered(true);
$reorder = $order_model->initFromOrder($orig_order);
$reorder->getQuote()->getShippingAddress()->collectTotals();
$reorder->getQuote()->getShippingAddress()->save();
$reorder->createOrder();
} catch (Exception $e) {
}
When I ran this script, I didn't get an error message. However if you get the error message below, most likely you are using the wrong order ID (hint entity_id = order ID)
PHP Fatal error: Call to a member function getData() on a non-object in app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php on line 333
Speeding this up a little, I decided to rewrite the script, and soon after I started to get this error:
PHP Fatal error: Uncaught exception 'Varien_Exception' with message 'Invalid method Mage_Sales_Model_Order_Address::collectShippingRates
So I had to put some additional logic in here for shipping and I ended up with:
<?php
include_once 'app/Mage.php';
Mage::app();
$orderId= '1'; //Think of entity_id, not the preformatted ID of 1000000001
$order = Mage::getModel('sales/order')->load($orderId);
$model = Mage::getSingleton('adminhtml/sales_order_create');
$order->setReordered(true);
$reorder = $model->initFromOrder($order);
//We needed additional logic for shipping rates
$reorder->getQuote()->getShippingAddress()
->setShippingMethod($order->getShippingMethod())
->setCollectShippingRates(true)
->collectShippingRates()
->collectTotals()
->save();
$reorder->createOrder();
I ran this two times and didn't see any errors. So I decided to go into the admin panel and look at my sales and I saw:
