0

I want to remove the reviews summary from the reviews form on product pages.

I had some code that works for 2.4.3 but I'm trying to get it to work with 2.4.6

This is where I have got to but I get the error:

"Magento\Framework\Validator\ValidateException: Class "SOMETHING\ReviewDeleteSummary\Rewrite\Magento\Review\Model\NotEmpty" does not exist "

namespace SOMETHING\ReviewDeleteSummary\Rewrite\Magento\Review\Model;

use Magento\Framework\Validator\ValidatorChain;

class Review extends \Magento\Review\Model\Review
{
    public function validate()
    {
     
        $errors = [];

    if (!ValidatorChain::is($this->getNickname(), NotEmpty::class)) {
            $errors[] = __('Please enter a nickname.');
        }

    if (!ValidatorChain::is($this->getDetail(), NotEmpty::class)) {
            $errors[] = __('Please enter a review.');
        }

      
    if (empty($errors)) {
            return true;
        }
  
    return $errors;
    }
}

2 Answers 2

0

You need to add the following use instruction :

use Magento\Framework\Validator\NotEmpty;
2
  • That now gives me a 302 on /review/product/post/id/222/ but nothing in the exception.log Jun 26, 2023 at 10:10
  • This might come from another error somewhere else in the module, but the initial error was because of the missing use instruction.
    – Cladiuss
    Jun 26, 2023 at 11:54
0

You can add the following code :

namespace SOMETHING\ReviewDeleteSummary\Rewrite\Magento\Review\Model;

use Magento\Framework\Validator\ValidatorChain;
use Magento\Framework\Validator\NotEmpty as NotEmptyValidator;

class Review extends \Magento\Review\Model\Review
{
   public function validate()
    {
      $errors = [];

      $notEmptyValidator = new NotEmptyValidator();

      if (!$notEmptyValidator->isValid($this->getNickname())) {
         $errors[] = __('Please enter a nickname.');
      }

      if (!$notEmptyValidator->isValid($this->getDetail())) {
        $errors[] = __('Please enter a review.');
      }

      if (empty($errors)) {
         return true;
      }

      return $errors;
    }
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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