Recently I have migrated our website. I have imported the orders however they all by default were changed to complete and no invoice was created.
The main problem is that it works great with one order number, more order numbers comma-delimited get me the PHP error.
Parse error: syntax error, unexpected ',' in /home/alphalasulaco/public_html/inv-cre.php on line 5
I have compiled the following script to change the order to processing and allow invoice creation.
<?php
require_once('./app/Mage.php');
Mage::app();
$orderNumbers = 100124858,100124857;
$order = Mage::getModel("sales/order")->load($orderNumbers);
$collection = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('increment_id', array('in' => $orderNumbers));
foreach ($collection as $order) {
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING)
->setStatus(Mage_Sales_Model_Order::STATE_PROCESSING)
->save();
}
try {
if($order->canInvoice())
{
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
if ($invoice->getTotalQty()) {
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
$invoice->register();
$transaction = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transaction->save();
Mage::getSingleton('core/session')->addSuccess('Invoice Created Successfully.');
}else{
Mage::getSingleton('core/session')->addError('Can not create invoice without Product Quantities');
}
}else{
Mage::getSingleton('core/session')->addError('Can not create invoice');
}
}
catch (Mage_Core_Exception $e) {
echo $e->getMessage();
}
?>