Skip to content

Change the variable to the coming function from before plugin

I would like to change the variable – $validate to false from before the plugin. May I know how to do it?

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

<?php

namespace MyModuleReviewCheckPlugin;

use MagentoFrameworkMessageManagerInterface as MessageManagerInterface;

class ReviewModel {

protected $messageManager;

protected $request;

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

}

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'));

    }
    else {
        return $this;
    }

   }
}

MagentoReviewControllerProductPost:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
 namespace MagentoReviewControllerProduct;

 use MagentoFrameworkAppActionHttpPostActionInterface as HttpPostActionInterface;
 use MagentoReviewControllerProduct as ProductController;
 use MagentoFrameworkControllerResultFactory;
 use MagentoReviewModelReview;

 /**
  * Class Post
  */
 class Post extends ProductController implements HttpPostActionInterface
 {
/**
 * Submit new review action
 *
 * @return MagentoFrameworkControllerResultRedirect
 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
 * @SuppressWarnings(PHPMD.NPathComplexity)
 */
public function execute()
{
    /** @var MagentoFrameworkControllerResultRedirect $resultRedirect */
    $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
    if (!$this->formKeyValidator->validate($this->getRequest())) {
        $resultRedirect->setUrl($this->_redirect->getRefererUrl());
        return $resultRedirect;
    }

    $data = $this->reviewSession->getFormData(true);
    if ($data) {
        $rating = [];
        if (isset($data['ratings']) && is_array($data['ratings'])) {
            $rating = $data['ratings'];
        }
    } else {
        $data = $this->getRequest()->getPostValue();
        $rating = $this->getRequest()->getParam('ratings', []);
    }
    if (($product = $this->initProduct()) && !empty($data)) {
        /** @var MagentoReviewModelReview $review */
        $review = $this->reviewFactory->create()->setData($data);
        $review->unsetData('review_id');

        $validate = $review->validate();
        if ($validate === true) {
            ....
}
}