Skip to content

Unable to redirect from plugin

I am trying to redirect from plugin file but seems no response. Anyone can help?

app/code/Myvendor/ReviewCheck/Plugin/ReviewModel.php

<?php

 namespace MyvendorReviewCheckPlugin;

 use MagentoFrameworkMessageManagerInterface as MessageManagerInterface;

 use MagentoFrameworkViewElementTemplateContext;

 class ReviewModel {

protected $messageManager;

protected $request;

protected $redirectFactory;

public function __construct(
    MessageManagerInterface  $messageManager,
    MagentoFrameworkAppRequestHttp $request,
    MagentoFrameworkControllerResultRedirectFactory $redirectFactory
)
{
    $this->messageManager=$messageManager;
    $this->request=$request;
    $this->redirectFactory=$redirectFactory;

}

public function beforeExecute(MagentoReviewControllerProductPost $subject) {

    $nickNameChecker = $this->request->getPostValue("nickname");

    if(strpos($nickNameChecker,"-")){

        $this->messageManager->addErrorMessage('Nickname cant has dash'.date('Y-m-d H:i:s'));
        $resultRedirect = $this->redirectFactory->create();
        $resultRedirect->setPath('checkout/');
        return $resultRedirect;

    }
    else {
        return $this;
    }

}

}