Для Prestashop 1.5
1. Добавление нового хука "productListRating" в файл productcomments.php
public function install()
{
if (!file_exists(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE))
return false;
else if (!$sql = file_get_contents(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE))
return false;
$sql = str_replace(array('PREFIX_', 'ENGINE_TYPE'), array(_DB_PREFIX_, _MYSQL_ENGINE_), $sql);
$sql = preg_split("/;\s*[\r\n]+/", trim($sql));
foreach ($sql as $query)
if (!Db::getInstance()->execute(trim($query)))
return false;
if (parent::install() == false ||
!$this->registerHook('productTab') ||
!$this->registerHook('extraProductComparison') ||
!$this->registerHook('productTabContent') ||
!$this->registerHook('header') ||
!$this->registerHook('productOutOfStock') ||
!$this->registerHook('productListRating') ||
!Configuration::updateValue('PRODUCT_COMMENTS_MINIMAL_TIME', 30) ||
!Configuration::updateValue('PRODUCT_COMMENTS_ALLOW_GUESTS', 0) ||
!Configuration::updateValue('PRODUCT_COMMENTS_MODERATE', 1))
return false;
return true;
}
2. Код хука "productListRating" для подсчета рейтинга и вывода шаблона блока со звездами.
function hookProductListRating($params)
{
require_once(dirname(__FILE__).'/ProductComment.php');
require_once(dirname(__FILE__).'/ProductCommentCriterion.php');
$id_product = $params['idproduct'];
$product_average = 0;
$grades = ProductComment::getAveragesByProduct($id_product, $this->context->language->id);
$criterions = ProductCommentCriterion::getByProduct($id_product, $this->context->language->id);
$grade_total = 0;
if (count($grades) > 0)
{
foreach ($criterions as $criterion)
{
if (isset($grades[$criterion['id_product_comment_criterion']]))
{
$grade_total += (float)($grades[$criterion['id_product_comment_criterion']]);
}
}
$product_average = $grade_total / count($criterions);
}
$this->context->smarty->assign('average_total', (int)$product_average);
return $this->display(__FILE__, '/product-list.tpl');
}
3. Шаблон блока рейтинга, показ количества звезд, product-list.tpl
<div class="star_content clearfix">
{section name="i" start=0 loop=5 step=1}
{if $smarty.section.i.index lt $average_total}
<div class="star star_on"><a href=""></a></div>
{else}
<div class="star"><a href=""></a></div>
{/if}
{/section}
</div>
4. Стили для этого шаблона, можно добавить в файл product_list.css
#product_list li h3
{
padding:0 0 10px 0;
font-size:13px;
color:#000
}
#product_list li .star_content
{
display: inline-block;
margin-bottom: 10px;
}
5. Добавление вывода блока рейтинга на странице категорий, шаблон product-list.tpl
{hook h='productListRating' idproduct=$product.id_product}