I need to invoice my order automatically whenever shipment is done, but if say I ship only one item of multiple items order then invoice should also be created for only that item not for all. I am using following code after setting a observer whenever shipped but it is invoicing all items even if I ship just one:
public function invoicedStatusChange($observer) { $shipment = $observer->getEvent()->getShipment(); $order = $shipment->getOrder(); if($order->canInvoice()) { $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice(); $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE); $invoice->register(); $transactionSave = Mage::getModel('core/resource_transaction') ->addObject($invoice) ->addObject($invoice->getOrder()); $transactionSave->save(); } Thanks in advance