Jump to content

[FREE TUTORIAL] Display Product rating in the products list in Prestashop


Recommended Posts

  • 2 months later...

That's not exactly related as this is for the product list. Anyway yes, but you will need to use absolute positioning in the css as you want to put another thiong between the module's tpl divs. OR, you can edit the product_extra template of the comments module and add the print link there

Link to comment
Share on other sites

<script type="text/javascript">
$(function(){
$('a[href=#idTab5]').click(function(){
 $('*[id^="idTab"]').addClass('block_hidden_only_for_screen');
 $('div#idTab5').removeClass('block_hidden_only_for_screen');
 $('ul#more_info_tabs a[href^="#idTab"]').removeClass('selected');
 $('a[href="#idTab5"]').addClass('selected');
});
});
</script>
<div id="product_comments_block_extra">
{if $nbComments != 0}
<div class="comments_note">
 <span>{l s='Average grade' mod='productcomments'}&nbsp</span>
 <div class="star_content clearfix">
 {section name="i" start=0 loop=5 step=1}
  {if $averageTotal le $smarty.section.i.index}
   <div class="star"></div>
  {else}
   <div class="star star_on"></div>
  {/if}
 {/section}
 </div>
</div>
{/if}
<div class="comments_advices">
 {if $nbComments != 0}
 <a href="#idTab5">{l s='Read user reviews' mod='productcomments'} ({$nbComments})</a><br/>
 {/if}
 {if ($too_early == false AND ($logged OR $allow_guests))}
 <a class="open-comment-form" href="#new_comment_form">{l s='Write your review' mod='productcomments'}</a>
 {/if}
</div>
</div>
<!--  /Module ProductComments -->

 

post-374708-0-13793300-1371629458_thumb.jpg

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...
  • 4 months later...
  • 1 year later...
  • 1 year later...

Hello,

Many thanks for this tutorial.

 

It help me a lot.

I have installed it on my prestashop 1.6.1.6

 

I have made some changes in order to have reviews counting:

 

Here is the code:

// Product Stars On Product List  
public function hookProductInList($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);                        
// Reviews Counting
      $this->smarty->assign(array(
                'nbComments' => (int) ProductComment::getCommentNumber($id_product),
		));               
      return $this->display(__FILE__, '/product-list-rating.tpl');
  }
 }
// End Of Product Stars On Product List 

I only have PHP Notices:

Trying to get property of non-object in .........productcomments.tpl.php on line 196

Trying to get property of non-object in .........productcomments.tpl.php on line 200

Trying to get property of non-object in .........productcomments.tpl.php on line 203

Undefined index: product in ...cache/smarty/compile/...file.product-list-rating.tpl.php on line 58

 

Here is the code of the smarty productcomments.tpl.php

" height="<?php echo $_smarty_tpl->tpl_vars['mediumSize']->value['height'];?>
" width="<?php echo $_smarty_tpl->tpl_vars['mediumSize']->value['width'];?>
" alt="<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['product']->value->name, ENT_QUOTES, 'UTF-8', true);?>
" />
						<div class="product_desc">
							<p class="product_name">
								<strong><?php echo $_smarty_tpl->tpl_vars['product']->value->name;?>
</strong>
							</p>
							<?php echo $_smarty_tpl->tpl_vars['product']->value->description_short;?>

	

Here is the code of the smarty product-list-rating.tpl.php

 <?php if ($_smarty_tpl->getVariable('smarty')->value['section']['i']['index']<$_smarty_tpl->tpl_vars['average_total']->value) {?>
  <div class="star star_on"><a href="<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['product']->value['link'], ENT_QUOTES, 'UTF-8', true);?>
"></a></div>

I believe that is something wrong with tpl_vars['product'] but I do not know how to solve it

 

Any help?

Thank you.

Regards

Edited by StefArts (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...
  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...