cancel
Showing results for 
Search instead for 
Did you mean: 

Simple product invoice not created incase Bundle product and simple product ordered together

SOLVED

Simple product invoice not created incase Bundle product and simple product ordered together

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 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Simple product invoice not created incase Bundle product and simple product ordered together

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;
        }

 

View solution in original post

3 REPLIES 3

Re: Simple product invoice not created incase Bundle product and simple product ordered together

This issue came incase of cashondelivery payment method

Re: Simple product invoice not created incase Bundle product and simple product ordered together

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!

Problem solved? Click Accept as Solution!

Re: Simple product invoice not created incase Bundle product and simple product ordered together

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;
        }