1

I want to add conditions for review. If the review is already approved then restrict the functionality to stop the change the status of the review.

<?php
namespace Custom\Reviews\Plugin\Controller\Adminhtml\Product;
use Magento\Framework\App\RequestInterface;
use Magento\Review\Model\ReviewFactory;
use Webkul\Walletsystem\Model\WalletUpdateData;
class Save
{



    protected $request;

    protected $resource;

    protected $reviewFactory;

    /**
     * @var Webkul\Walletsystem\Model\WalletUpdateData
     */
    private $walletUpdate;
    private $walletHelper;
    /**
     * @var \Magento\Framework\Stdlib\DateTime\DateTime
    */
    protected $date;
            
    public function __construct(
        RequestInterface $request,
        \Magento\Framework\App\ResourceConnection $resource,
        ReviewFactory $reviewFactory,
        WalletUpdateData $walletUpdate,
        \Webkul\Walletsystem\Helper\Data $walletHelper,
        \Magento\Framework\Stdlib\DateTime\DateTime $date
    ){
        $this->request = $request;
        $this->_resource = $resource;
        $this->reviewFactory = $reviewFactory;
        $this->walletUpdate = $walletUpdate;
        $this->walletHelper = $walletHelper;
        $this->date = $date;
    }
    public function aroundExecute(
        \Magento\Review\Controller\Adminhtml\Product\Save $subject,
        callable $proceed
    ){
        $reviewId = $this->request->getParam('id');
        $review = $this->reviewFactory->create()->load($reviewId);
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/satish.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $timestamp = date("Y-m-d h:i:s");
        if ($review['status_id'] == 1) { // if review already Approved then no need to change the status
            // code...
            $logger->info("Already approved want to show msg like this status not be changed.");
        }else{

            $logger->info("functionality added while approving");

        }

        $result = $proceed();

        return $result;
    }
}
4
  • can you describe your requirement in some more details. Oct 25, 2021 at 6:31
  • I want to stop the execution of review update if review already approved. dont want to change the approved to Pending again Oct 25, 2021 at 6:34
  • how can we stop the execution using plugin based on condition. I am using aroundExecute plugin method. Oct 25, 2021 at 6:36
  • share the code which you try and also share the issue which you facing into that one? Oct 25, 2021 at 6:42

0

Your Answer

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