I am trying to create invoice using customer token. But getting following error.

No such entity with orderId = 31

This error is generated after execution of following code.

$transactionSave = $this->_transaction->addObject(
$transactionSave->save(); //This statement causes error

How to resolve this issue?


hi Please try below code for generate Invoice programatically

        $orderId = 31; //order id for which want to create invoice
        $order = $this->_orderRepository->get($orderId);
        if($order->canInvoice()) {
            $itemsArray = ['80'=>2]; //here 80 is order item id and 2 is it's quantity to be invoice
            $shippingAmount = '10.00';
            $subTotal = '110.00';
            $baseSubtotal = '110.00';
            $grandTotal = '110.00';
            $baseGrandTotal = '110.00';
            $invoice = $this->_invoiceService->prepareInvoice($order, $itemsArray);
            $transactionSave = $this->_transaction->addObject(
            //send notification code
                __('Notified customer about invoice #%1.', $invoice->getId())

Please refer below link for that :- https://webkul.com/blog/how-to-programmatically-create-invoice-in-magento2/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.