0

How to redirect from around plugin to another page with an error ?

0

Not tested but this might work for you. The ManagerInterface class will set the error message and response class will help in redirecting to specific url.

<?php
namespace Vendor\ModuleName\Plugin;

class MyPluginClass
{
    private $response;

    private $messageManager;

    public function __construct
    (
        \Magento\Framework\Message\ManagerInterface $messageManager,
        \Magento\Framework\App\Response\Http $response
    )
    {
        $this->messageManager = $messageManager;
        $this->response = $response;
    }

    public function aroundSomeMethod($subject, $proceed, $someThingForTrue){
        if($someThingForTrue){
            $this->messageManager->addErrorMessage(__('There seems to be some error'));
            $url = 'http://mystoreurl.com';
            $this->response->setRedirect($url);
            $this->response->sendResponse();
        }
    }
}
  • I will check and let u know. Thanks for the response. – gajjala sandeep Jan 4 at 7:15

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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