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?

2 Answers 2


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

Hope this helps.

  • geting error "SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (magento22.sales_order_status_history, CONSTRAINT SALES_ORDER_STATUS_HISTORY_PARENT_ID_SALES_ORDER_ENTITY_ID FOREIGN KEY (parent_id) REFERENCES sales_order (entity_id) ON DELETE CAS), query was: INSERT INTO sales_order_status_history (is_customer_notified, comment, status, entity_name) VALUES (?, ?, ?, ?)", Mar 1, 2018 at 12:22
  • This can't work, because addStatusHistoryComment() returns a OrderStatusHistoryInterface object, so the following methods in your snippets are not chainable.
    – ermannob
    Oct 31, 2018 at 14:21

Alternative way

// better to init related instances in __construct
$factory = \Magento\Framework\App\ObjectManager::getInstance()
$repository = \Magento\Framework\App\ObjectManager::getInstance()

// $order - your order instance
$history = $factory->create();
    ->setComment('Your Comment')


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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