I would like to programmatically create new orders from existing orders by their id and send new order confirmations by mail. The new orders need to contain all the information the old ones had (Items, Customer, Shipping Information etc.):

include_once 'app/Mage.php';

//some existing order ids
$orderIds= array('911', '1106', '926');

foreach($orderIds as $orderId){

    /* @var Mage_Sales_Model_Order $order */
    $order = Mage::getModel('sales/order')->load($orderId)

    /* @var Mage_Sales_Model_Quote $quote */
    $quote = Mage::getModel('sales/quote')

    /* @var Mage_Adminhtml_Model_Sales_Order_Create $model */
    $model = Mage::getModel('adminhtml/sales_order_create')

    /* @var Mage_Sales_Model_Order $newOrder */
    $newOrder = $model->createOrder();


Unfortunately Magento keeps the Customer information while looping through the order IDs, so the emails are all sent to the customer of the first order (in this case the one with the id 911). Also, the order items seem to add up in the cart, so the last order which is placed contains all the order items of the previous orders... What am I doing wrong?

  • Bledert, I am not really sure what the question is that you are asking. Can you please clarify? You want to reorder orders by id but do not want the order details to remain the same? Thanks Commented Jan 9, 2015 at 14:07
  • No, the order details can stay the same! It works perfectly if I only have one order ID in $orderIds, but as soon as there are mutiple order ids, the customer in the following orders remain the same :(
    – biedert
    Commented Jan 9, 2015 at 15:13
  • From the top of my head, the current customer has an object cache. Should become apparent when you trace assignCustomer().
    – user4351
    Commented Jan 10, 2015 at 9:46
  • Yep, that's what I thought... But $quote->getCustomerEmail() actually gives me the correct email, but $newOrder->getCustomerEmail() doesn't. So I think $model->setQuote() doesn't really work after $model is initiated by $order. Any other suggestions to clear the object cache?
    – biedert
    Commented Jan 12, 2015 at 9:32
  • 1
    So really nobody has an answer on that? :(
    – biedert
    Commented Jan 15, 2015 at 9:06

2 Answers 2


Magento uses lots of singletons and assumes that certain actions are only executed once.

If you take a look at Mage_Adminhtml_Model_Sales_Order_Create, you will find this one:

public function __construct()
    $this->_session = Mage::getSingleton('adminhtml/session_quote');

You can reset singletons like this:


If it still does not work, walk through the code, there might be other relevant singletons.


Try bellow script


    public function index()    
        //some existing order ids
        $orderIds= array('911', '1106', '926');
        foreach($orderIds as $orderId) {
            $order =  Mage::getModel('sales/order')->load($orderId);
            if (!$order->getId()) {
                echo 'Invalid order id'.$orderId;

            $quoteId = $order->getQuoteId();
            $storeId = $order->getStoreId();
            $quote = Mage::getModel("sales/quote")

            try {
                /** @var $service Mage_Sales_Model_Service_Quote */
                $service = Mage::getModel('sales/service_quote', $quote);

                $order = $service->getOrder();
                if ($order) {
                    try {
                    } catch (Exception $e) {
            } catch (Mage_Core_Exception $e) {

           echo $order->getIncrementId();

$obj = new ORDERCREATE();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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