File: /home4/cca63905/public_html/nueva/modules/pmproductvideoreviews/controllers/front/ajax.php
<?php
/**
* rec.reviews
*
* @author Presta-Module.com <support@presta-module.com> - https://www.presta-module.com
* @copyright Presta-Module - https://www.presta-module.com
* @license see file: LICENSE.txt
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*/
if (!defined('_PS_VERSION_')) {
exit;
}
use PrestaModule\ProductVideoReviews\Utils;
use PrestaModule\ProductVideoReviews\Ratings;
class pmproductvideoreviewsAjaxModuleFrontController extends ModuleFrontController
{
public $ssl = true;
protected $jsonOutput = [];
public $ajax = true;
public function init()
{
parent::init();
$this->ajax = true;
}
public function displayAjax()
{
$sAction = Tools::getValue('action', 'undefined');
if (!empty($sAction) && method_exists($this, 'ajaxProcess' . Tools::toCamelCase($sAction))) {
$this->{'ajaxProcess' . Tools::toCamelCase($sAction)}();
} else {
$this->errors[] = $this->module->l('Undefined action', 'ajax');
}
}
protected function ajaxProcessSortReview()
{
$token = Tools::getValue('token');
$module_token = Tools::getToken(false);
$product_id = (int)Tools::getValue('id_product', Tools::getValue('idProduct', 0));
if (empty($token) || $token != $module_token || empty($product_id)) {
die;
}
$sort = Tools::getValue('pvrRwSort');
$show_more_value = Tools::getValue('iShowMore');
$reviews = Ratings::getProductReviews($product_id, $show_more_value, $sort);
if (!empty($reviews)) {
$reviews_details = Utils::formatReviewsDetail($reviews, $product_id);
$show_more_data = Utils::showMoreData($reviews, (int)$reviews_details['total_reviews'], $show_more_value);
Context::getContext()->smarty->assign([
'reviews' => $show_more_data['display_reviews'],
'show_more_value' => $show_more_data['show_more_value'],
'review_per_ligne' => (int)Configuration::get('PVR_PRODUCT_REVIEW_LINES'),
'total_review' => count(Ratings::getProductReviews($product_id)),
'reviews_detail' => $reviews_details['reviews_detail'],
'has_show_more' => $show_more_data['has_show_more'],
'max_rating' => 5,
'show_more_value_default' => $show_more_data['default_value'],
]);
$this->jsonOutput['outputHTML'] = $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/hook/partials/reviews.tpl');
die(json_encode($this->jsonOutput));
}
}
protected function ajaxProcessSeeMore()
{
$token = Tools::getValue('token');
$module_token = Tools::getToken(false);
$product_id = (int)Tools::getValue('id_product', Tools::getValue('idProduct', 0));
if (empty($token) || $token != $module_token || empty($product_id)) {
die;
}
$show_more_number = !empty(Tools::getValue('iShowMore')) ? Tools::getValue('iShowMore') + (int)Configuration::get('PVR_PRODUCT_REVIEW_LINES') : (int)Configuration::get('PVR_PRODUCT_REVIEW_LINES');
$show_more_value = Tools::getValue('iShowMore', (int)Configuration::get('PVR_PRODUCT_REVIEW_LINES'));
$sort = Tools::getValue('pvrRwSort');
$show_more_value_with_sort = Tools::getValue('show_more_value_with_sort');
$reviews = Ratings::getProductReviews($product_id, (int)$show_more_number, $sort);
if (!empty($reviews)) {
$reviews_details = Utils::formatReviewsDetail($reviews, $product_id);
$show_more_data = Utils::showMoreData($reviews, (int)$reviews_details['total_reviews'], $show_more_value);
Context::getContext()->smarty->assign([
'reviews' => $show_more_data['display_reviews'],
'show_more_value' => $show_more_data['show_more_value'],
'review_per_ligne' => (int)Configuration::get('PVR_PRODUCT_REVIEW_LINES'),
'total_review' => count(Ratings::getProductReviews($product_id)),
'reviews_detail' => $reviews_details['reviews_detail'],
'has_show_more' => $show_more_data['has_show_more'],
'max_rating' => 5,
'show_more_value_default' => $show_more_data['default_value'],
]);
$this->jsonOutput['outputHTML'] = $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/hook/partials/reviews.tpl');
die(json_encode($this->jsonOutput));
}
}
}