I'm querying for specific memberships that were previously ordered and reordering them via the admin reorder functions. However, when the foreach goes through a first full cycle and successfully places a reorder, the second cycle starts and tries to reorder the second order and fails because some of the original order data exists even though the next order data has been set already.

This is what I am trying to do:

foreach($memberpackageCollection as $mpcKey => $memberpackage) {
    try {
        $orderId = $memberpackage->getOrderIds();
        $personsOrder = Mage::getModel('sales/order')->load($orderId);

        /* Set different payment method */

        $orderModel = Mage::getSingleton('adminhtml/sales_order_create');
    catch (Exception $e) {

Error occurs after second time it loops.

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '100006914-1' for key 'UNQ_XYYXSALES_FLAT_ORDER_INCREMENT_ID''

I understand that the error is produced because there is a duplicate increment ID. This is because it tries to reorder on the original order and not on the next one. As you can see from the code I show, I am loading a new order and trying to create a reorder on that order. Somehow I need to clear the session data that appears to be set in the model adminhtml/sales_order_create that seems to remaining in there for each order.

  • Did you try to use Mage::getModel() instead of Mage::getSingleton('adminhtml/sales_order_create')? – Fabian Blechschmidt Dec 7 '13 at 23:37
  • Mage::getModel() would make more sense in this case. I've replace it with getModel(), and it seems to be doing the exact same thing. – RNickMcCandless Dec 9 '13 at 6:02

Add this at the end of your try block:


For some reason the backend reordering system works with sessions. This will clear the session data and let you start fresh on your second iteration.

  • hi, maybe this is also relevant, seems that you can only reorder a old order only one time. If you take a look at createOrder()-Method: 'increment_id' => $originalId.'-.$oldOrder->getEditIncrement()+1) – Stefan Bothner Oct 29 '14 at 9:41
  • 1
    @StefanBothner, you can reorder/edit an order as many times you want. The EditIncrement field is incremented and kept on all parent/child orders at same max increment value. There should be no problem in reordering on the original order, and not on a child of it. – Mihai MATEI Mar 10 '15 at 21:03

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.