I have created order with one simple product and one bundle product. A bundle product invoice is created, but simple product item status is ordered.
Magento doesn't handle this
Solved! Go to Solution.
To resolve this need to override core file function
'/vendor/magento/module-sales/Model/Service/InvoiceService.php'
Added one more else if condition
elseif (!empty($qtys) && $orderItem->getProductType() != Type::TYPE_BUNDLE) { $qty = $orderItem->getQtyToInvoice(); }
/** * Creates an invoice based on the order and quantities provided * * @param Order $order * @param array $qtys * @return \Magento\Sales\Model\Order\Invoice * @throws \Magento\Framework\Exception\LocalizedException */ public function prepareInvoice(Order $order, array $qtys = []) { $invoice = $this->orderConverter->toInvoice($order); $totalQty = 0; $qtys = $this->prepareItemsQty($order, $qtys); foreach ($order->getAllItems() as $orderItem) { if (!$this->_canInvoiceItem($orderItem, $qtys)) { continue; } $item = $this->orderConverter->itemToInvoiceItem($orderItem); if (isset($qtys[$orderItem->getId()])) { $qty = (double) $qtys[$orderItem->getId()]; } elseif ($orderItem->isDummy()) { $qty = $orderItem->getQtyOrdered() ? $orderItem->getQtyOrdered() : 1; } elseif (empty($qtys)) { $qty = $orderItem->getQtyToInvoice(); }elseif (!empty($qtys) && $orderItem->getProductType() != Type::TYPE_BUNDLE) { $qty = $orderItem->getQtyToInvoice(); } else { $qty = 0; } $totalQty += $qty; $this->setInvoiceItemQuantity($item, $qty); $invoice->addItem($item); } $invoice->setTotalQty($totalQty); $invoice->collectTotals(); $order->getInvoiceCollection()->addItem($invoice); return $invoice; }
This issue came incase of cashondelivery payment method
Hi @jyoti_thakur
In this case you need to create observer "sales_order_invoice_pay" where you can customize invoice by programming.
Kindly refer below link for your solution:
https://www.mageplaza.com/devdocs/magento-2-create-invoice-programmatically.html
If issue resolve, kindly click on 'Kudos' & Accept as Solution!
To resolve this need to override core file function
'/vendor/magento/module-sales/Model/Service/InvoiceService.php'
Added one more else if condition
elseif (!empty($qtys) && $orderItem->getProductType() != Type::TYPE_BUNDLE) { $qty = $orderItem->getQtyToInvoice(); }
/** * Creates an invoice based on the order and quantities provided * * @param Order $order * @param array $qtys * @return \Magento\Sales\Model\Order\Invoice * @throws \Magento\Framework\Exception\LocalizedException */ public function prepareInvoice(Order $order, array $qtys = []) { $invoice = $this->orderConverter->toInvoice($order); $totalQty = 0; $qtys = $this->prepareItemsQty($order, $qtys); foreach ($order->getAllItems() as $orderItem) { if (!$this->_canInvoiceItem($orderItem, $qtys)) { continue; } $item = $this->orderConverter->itemToInvoiceItem($orderItem); if (isset($qtys[$orderItem->getId()])) { $qty = (double) $qtys[$orderItem->getId()]; } elseif ($orderItem->isDummy()) { $qty = $orderItem->getQtyOrdered() ? $orderItem->getQtyOrdered() : 1; } elseif (empty($qtys)) { $qty = $orderItem->getQtyToInvoice(); }elseif (!empty($qtys) && $orderItem->getProductType() != Type::TYPE_BUNDLE) { $qty = $orderItem->getQtyToInvoice(); } else { $qty = 0; } $totalQty += $qty; $this->setInvoiceItemQuantity($item, $qty); $invoice->addItem($item); } $invoice->setTotalQty($totalQty); $invoice->collectTotals(); $order->getInvoiceCollection()->addItem($invoice); return $invoice; }