cancel
Showing results for 
Search instead for 
Did you mean: 

add comment to invoice history

add comment to invoice history

Hello,

 

I would like to add some automated comment to the history of an invoice. How do I do that?
This code is not working:

 

$invoice->addComment ("Versand mit ".$in_carrier." unter der Nummer ".$in_paketnummer."\n",false,true);
$invoice->save();
2 REPLIES

Re: add comment to invoice history

Hello,

 

I don't know how you get invoice object.

 

 

 

use Magento\Framework\App\ObjectManager;

use Magento\Sales\Api\InvoiceRepositoryInterface;

$invoiceRepository = ObjectManager::getInstance()
->get(InvoiceRepositoryInterface::class);
$invoice = $invoiceRepository->get(1); //id of invoice
$invoice->addComment("testing comment",false,true);
 $invoice->save();

More info you can find Magento\Sales\Controller\Adminhtml\Order\Invoice\AddComment

 

Hope it will help you.

 

If it will work then mark as a solution or give kudos.

Re: add comment to invoice history

In Magento 2, There are three files which you need to follow up for invoice comment,

Refer below all three files and check with your code,

1. AddComment.php

2. Save.php

3.InvoiceDocumentFactory.php

 

Above all three files use Invoice comment so please refer above files.

 

 

If Issue Solved, Click Kudos/Accept As solutions.