Here's the scenario. For example $oldOrder
has an increment ID of 100000044
if($oldOrder->canCancel()) {
$order->cancel();
$order->save();
}
When I call the above, for some reason, it's messing up the increment ID, which is becoming 000000062
.
In addition, if I create a new order, it will have the same increment ID of the old ordder, which is 100000044
, even though the increment ID is assumed to be unique.
This is causing an issue, as the increment ID might have been used in a call to the 3rd party payment gateway previously, and linked from their side to the old order, as the increment ID is supposed to be unique to each order.
Am I doing something wrong? How do I fix this? I noticed that the increment ID doesn't mess up when I manually cancel it from the admin page, instead of the php script..
I'm creating an order the following way:
$billingAddress = $quote->getBillingAddress()->addData($billingAddress);
$shippingAddress = $quote->getShippingAddress()->addData($shippingAddress);
$shippingAddress->setCollectShippingRates(true)->collectShippingRates()
->setShippingMethod('flatrate_flatrate')
->setPaymentMethod('purchaseorder');
$quote->setBillingAddress($billingAddress);
$quote->setShippingAddress($shippingAddress);
$quote->getPayment()->importData(array('method' => 'purchaseorder'));
$quote->collectTotals()->save();
$quote->setReservedOrderId(null); //----This solved the increment issue.
$quote->reserveOrderId();
$quote->save();
$service = Mage::getModel('sales/service_quote', $quote);
$service->submitAll();
$order = $service->getOrder();
// Mage::getSingleton('checkout/session')->setOrderId($order->getId());
//$quote->setIsActive(0)->save();
return $order;