how can we stop the execution using plugin based on the condition. I am using aroundExecute plugin method.
<?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;
}
}