Skip to content

Instantly share code, notes, and snippets.

@mykehsd
Created February 28, 2013 23:39
Show Gist options
  • Select an option

  • Save mykehsd/5061127 to your computer and use it in GitHub Desktop.

Select an option

Save mykehsd/5061127 to your computer and use it in GitHub Desktop.
/**
* This script simulates a single sku invoice.
* It shouldn't be possible via pbridge/payflowpro
* but the service_order object allows it
*/
print "Enter orderid: ";
$orderId= trim(fgets(STDIN));
$order = Mage::getModel('sales/order');
$order->load ( $orderId );
// First we prime our shipped items to include 0 units.
foreach ($order->getAllItems() as $item)
$itemsShipped[ $item->getId() ] = 0;
// Lets ship the first invoice-able item
foreach ($order->getAllItems() as $item) {
if ($item->canInvoice()) {
$itemsShipped[$item->getId()] = 1;
break;
}
}
// Now lets actually generate the invoice
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice($itemsShipped);
if (!$invoice->getTotalQty()) {
Mage::throwException('Cannot create an invoice without products.');
}
$invoice->setRequestedCaptureCase('online');
$invoice->register();
$invoice->getOrder()->setCustomerNoteNotify(false);
$invoice->getOrder()->setIsInProcess(true);
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder())
->save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment