I have added a below line in my observer file for the event checkout_cart_save_after

$this->_messageManager->addNotice(__("A Notice Message"));

Every time it hits observer, it displayes more than 1 message in frontend. I need to display only one message at a time. Can anyone pls help to clear the messages in message manager?

My observer logic is below:

 public function execute(Observer $observer)
        allowCheckout = 1;
          //custom logic......
         if($allowCheckout == 0){
           $this->_messageManager->addNotice(__("A Notice Message"));



So Everytime when the event occurs it goes to observer and displays message manager notice message. It displays more than one message. I want only once the message to be displayed

  • Can you share your code of observer, what you have try? Commented Sep 14, 2018 at 14:18
  • @Dhiren Vasoya. I have updated my question with observer code
    – Pavithra
    Commented Sep 15, 2018 at 3:19

2 Answers 2


Try the following code:

$this->_messageManager->getMessages(true); //this will clear your messageManager container
$this->_messageManager->addNotice(__("A Notice Message"));

Try it with CookieManager.

public function __construct(
        \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
        $this->cookieManager = $cookieManager;


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.