This could happen when bundled products and simple products are mixed in the order.
To solve this, override the Invoiceservice.php from vendor/magento/module-sales/Model/Service/InvoiceService.php and change the below functions codes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
public function prepareInvoice(Order $order, array $qtys = []) { $isQtysEmpty = empty($qtys); $invoice = $this->orderConverter->toInvoice($order); $totalQty = 0; $qtys = $this->prepareItemsQty($order, $qtys); foreach ($order->getAllItems() as $orderItem) { if (!$this->_canInvoiceItem($orderItem, $qtys)) { continue; } if (isset($qtys[$orderItem->getId()])) { $qty = (double) $qtys[$orderItem->getId()]; } elseif ($orderItem->isDummy()) { $qty = $orderItem->getQtyOrdered() ? $orderItem->getQtyOrdered() : 1; } elseif ($isQtysEmpty) { $qty = $orderItem->getQtyToInvoice(); } else { $qty = 0; } $item = $this->orderConverter->itemToInvoiceItem($orderItem); $this->setInvoiceItemQuantity($item, $qty); $invoice->addItem($item); $totalQty += $qty; } $invoice->setTotalQty($totalQty); $invoice->collectTotals(); $order->getInvoiceCollection()->addItem($invoice); return $invoice; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
private function prepareItemsQty(Order $order, array $qtys = []) { foreach ($order->getAllItems() as $orderItem) { if (isset($qtys[$orderItem->getId()])) { if ($orderItem->isDummy() && $orderItem->getHasChildren()) { $qtys = $this->prepareItemQty($orderItem, $qtys); } } else { if (isset($qtys[$orderItem->getParentItemId()])) { $qtys[$orderItem->getId()] = $qtys[$orderItem->getParentItemId()]; } } } return $qtys; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
private function prepareItemQty(\Magento\Sales\Api\Data\OrderItemInterface $orderItem, &$qtys) { /** @var OrderItemInterface $childOrderItem */ foreach ($orderItem->getChildrenItems() as $childOrderItem) { if (!isset($qtys[$childOrderItem->getItemId()])) { $productOptions = $childOrderItem->getProductOptions(); if (isset($productOptions['bundle_selection_attributes'])) { $bundleSelectionAttributes = $this->serializer ->unserialize($productOptions['bundle_selection_attributes']); $qtys[$childOrderItem->getItemId()] = $bundleSelectionAttributes['qty'] * $qtys[$orderItem->getItemId()]; } } } return $qtys; } |
Once the changes will go live, the customer will have a complete invoice. None items will be missed.
[crayon-63e0a0b519e5b173778469/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.