0

I need an observer to be executed when I add a new comment to an order. On Magento 1.9 I used sales_order_save_after event but it does not exist on M2 anymore.

Anyone can help me with an event to do that or any idea to solve this ?

Basically the observer reads the new comment, looks for some content, if it is found it executes some code.

Thank you !

1 Answer 1

0

Instead of an observer, you could add an after plugin to the addCommentToStatusHistory function in vendor/magento/module-sales/Model/Order.php

There you could retrieve the comment added and execute your function if the comment match your content.

public function afterAddCommentToStatusHistory($subject, $result,$comment, $status , $isVisibleOnFront )
{
    if($comment=='something'){
       doSomething();
    }
    return $result;
}

Reference for plugin creation : https://devdocs.magento.com/guides/v2.2/extension-dev-guide/plugins.html

2
  • Great idea :) Let me test it and I will get back to you... thanks :D Commented Oct 7, 2019 at 19:35
  • It looks like it solve my problem. Sorry for taking long, too much work here. Thank you ! Commented Oct 11, 2019 at 17:01

Your Answer

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

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