2

I am using an observer on event sales_order_save_before to check for a condition and based on that condition I was to stop the save functionality.

Currently I am using it on Submit Comment in Sales Order view (Admin Panel)

My Observer execute function is called and condition is met. but it doesn't stop the save functionality when I raise error using throw new \ErrorException()

Is there any other way to completely stop the save order process?

1

This is what I learnt from magento 2 certification exam : the data that is sent to events should not be transformed. Events should be able to be run completely asynchronously, so around plugin can be used to stop logic. For Submit Comment create aroundExecute() for Magento\Sales\Controller\Adminhtml\Order\AddComment

public function aroundExecute(AddComment $subject, \Closure $proceed){
    //your statement;
    if (your statement) {
       proceed();
    }
    else{
       // stop original chain
       //adderrorMassage();
       redirect or throw Error;
       return;
    }

}
| improve this answer | |

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.