I am looking for help setting up a cron job that will look at all orders in all store views that have a status of "pending" created in the past X minutes and create an invoice and a shipment for those orders.
I would like to create the invoice but not create the shipment for one store view, creating the invoice and shipment for all of the others.
I hope this is clear. I have searched and found some examples, but none that apply to this situation.
EDIT:
I have started with this, but it doesn't seem to work yet. Just trying to get all orders that exist as 'pending', create an invoice, and create a shipment:
try { $orders = Mage::getModel('sales/order')->getCollection() ->addFieldToFilter( 'status', array( 'nin' => array('complete', 'canceled', 'processing', 'holded', 'fraud'), 'in' => 'pending', ) ) ->addAttributeToSelect('*'); } catch (Mage_Core_Exception $e) { } try { foreach ($orders as $eachorder) { $order = Mage::getModel("sales/order")->load($eachorder->getId()); if (!$order->canInvoice()) { Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.')); } $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice(); if (!$invoice->getTotalQty()) { Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.')); } $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE); $invoice->register(); $transactionSave = Mage::getModel('core/resource_transaction') ->addObject($invoice) ->addObject($invoice->getOrder()); $transactionSave->save(); $shipment = $order->prepareShipment(); if ($shipment) { $shipment->register(); $order->setIsInProcess(true); $transaction_save = Mage::getModel('core/resource_transaction') ->addObject($shipment) ->addObject($shipment->getOrder()) ->save(); } else { throw new Exception("Cant get shipment"); } $order->setState(Mage_Sales_Model_Order::STATE_COMPLETE); $order->save(); } } catch (Mage_Core_Exception $e) { }