We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    Magento 2 use show Success and Error Message Using Interface MagentoFrameworkMessageManagerInterface.

    You can set success message Using addSuccessMessage( ) and set error message using addErrorMessage( )function.

    You can directly fetch Object of MagentoFrameworkMessageManagerInterface in controller file but for other files like Plugin, Observer, Model, Block or Helper; you need to instantiate an object in your __construct( ) method.

     public function __construct(
        MagentoFrameworkMessageManagerInterface $messageManager
    ) {
        $this->messageManager = $messageManager;
    }

    Now you can set messages like below:

    $yourMessage = __('Your Error Message');
    $this->messageManager->addErrorMessage($message);
    $yourMessage = __('Your Warning Message');
    $this->messageManager->addWarningMessage($message);
    $yourMessage = __('Your Notice Message');
    $this->messageManager->addNoticeMessage($message);

     

    Fill the below form if you need any Magento relate help/advise/consulting.

    With Only Agency that provides a 24/7 emergency support.

      Get a Free Quote