Magento2 error message is not getting displayed, it gets displayed only after page refresh. I checked in console, the error msg is not getting added in messages:

  public function aroundExecute(
    \Magento\Catalog\Controller\Product\Compare\Add $subject,
    \Closure $proceed

      $count = $this->helper->getItemCount();
      if($count >= self::LIMIT_TO_COMPARE_PRODUCTS) {
            'You can add the compared products under 3 item(s)'

        /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
        $resultRedirect = $this->resultRedirectFactory->create();
        return $resultRedirect->setRefererOrBaseUrl();

      return $proceed();
  • Are you using the ajax to process the request? – Rahul Barot Mar 18 at 11:40
  • yes I guess, as I m using default add to compare – Arjun Mar 18 at 11:57
  • I don't think, because in default magento add to compare does not work on ajax. Check here magento.nublue.co.uk/gear/bags.html – Rahul Barot Mar 18 at 12:05
  • I was just checking I think it is because I am returning message via plugin so might be it is not working – Arjun Mar 18 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.