Magento – How to save order comment programmatically in magento2

magento2.2php-7quotesales-ordersales-quote

1)I'm creating custom order comment text box in sales->order->create new order .

2) Created order_comment column in sales_ order grid/quote.

3) I need to save order comment text box value into db.How to save comment in sales_order grid/quote table?

If anyone knows please explain me?

Best Answer

What you can do is use the \Magento\Sales\Api\OrderRepositoryInterface $order

Either use the order, or load it separately with

$comment = 'Add the comment you need...';
$order = $this->order->get(1); // Load your order
$order->addStatusHistoryComment($comment)
    ->setIsCustomerNotified(false)
    ->setEntityName('order')
    ->save(); 

Hope this helps.

Related Topic