I have modified form review as popup modal and have overrides the controller in my custom module, the review saved successfully in DB. I need to pass the response to the to JS in JSON format , Help me how to solve it. Here I have given my custom controller but it shows error while compiling
Errors during compilation: XXX\YYY\Controller\Index\Index Missed required argument coreRegistry in parent::__construct call. File: /var/www/html/magento220/app/code/XXX/YYY/Controller/Index/Index.php Total Errors Count: 1
[Magento\Framework\Validator\Exception] Error during compilation
Controller
<?php
namespace XXX\YYY\Controller\Index;
use Magento\Review\Model\Review;
use Magento\Framework\Controller\Result\JsonFactory;
class Index extends \Magento\Review\Controller\Product\Post
{
protected $_resultJsonFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context, JsonFactory $resultJsonFactory
)
{
$this->_resultJsonFactory = $resultJsonFactory;
parent::__construct($context);
}
public function execute()
{
$message = null;
$status = null;
if (!$this->formKeyValidator->validate($this->getRequest())) {
$message[] = "Invalid form key";
$status = 'failed';
} else {
$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', []);
}
echo 'sdfsdfsdfsdfsd';
print_r($data);
if (($product = $this->initProduct()) && !empty($data)) {
echo 'InsideLoops';
/** @var \Magento\Review\Model\Review $review */
$review = $this->reviewFactory->create()->setData($data);
$review->unsetData('review_id');
$validate = $review->validate();
if ($validate === true) {
try {
$review->setEntityId($review->getEntityIdByCode(Review::ENTITY_PRODUCT_CODE))
->setEntityPkValue($product->getId())
->setStatusId(Review::STATUS_PENDING)
->setCustomerId($this->customerSession->getCustomerId())
->setStoreId($this->storeManager->getStore()->getId())
->setStores([$this->storeManager->getStore()->getId()])
->save();
foreach ($rating as $ratingId => $optionId) {
$this->ratingFactory->create()
->setRatingId($ratingId)
->setReviewId($review->getId())
->setCustomerId($this->customerSession->getCustomerId())
->addOptionVote($optionId, $product->getId());
}
print_r($optionId);
$review->aggregate();
$message[] = __('You submitted your review for moderation.');
$status = 'success';
} catch (\Exception $e) {
$this->reviewSession->setFormData($data);
$message[] = __('We can\'t post your review right now.');
$status = 'failed';
}
} else {
$this->reviewSession->setFormData($data);
if (is_array($validate)) {
foreach ($validate as $errorMessage) {
$message[] = $errorMessage;
}
} else {
$message[] = __('We can\'t post your review right now.');
}
$status = 'failed';
}
}
}
$resultJson = $this->_resultJsonFactory->create()
->setData([
'messages' => $message,
'status' => $status,
]);
return $resultJson;
}