1

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?

0

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.

  • 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 (?, ?, ?, ?)", – Pushpendra Singh Mar 1 '18 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 '18 at 14:21

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.