Author Topic: Ratings in category view  (Read 5304 times)

Bruce Morgan

  • Full Member
  • ***
  • Posts: 672
Ratings in category view
« on: April 13, 2012, 02:05:27 am »
I have been playing around with this on my test site.  The default view for the categories will show the text "Average Rating:" and nothing to follow. The code for this starts around line 225.  There does not seem to be any code to call up the rating or display the stars.  The is some code that was commented out but that does not work.  I have attached a screen shot.  Is this a feature that has not yet been completed?  If so the "average rating" text should be dropped.

Anybody have this working correctly?  BTW I have a RT Zephyr template and none of the little icon like stars, arrows, et. are showing up.  Could use a litttle help here.

[attachment cleanup by admin]

Bruce Morgan

  • Full Member
  • ***
  • Posts: 672
Re: Ratings in category view
« Reply #1 on: April 24, 2012, 21:53:11 pm »
Bump.  Anybody?

Rixters

  • Beginner
  • *
  • Posts: 31
Re: Ratings in category view
« Reply #2 on: April 28, 2012, 18:42:03 pm »
Same here... Noticed that in the PHP file from catergory layout this part in disabled... Enabling it gives the following:

Code: [Select]
<img alt=" Stars" src="http://www.websiteaddress.com/assets//reviews/.gif">
Number of votes:

Maybe some more work needs te be done here..

Sonictech

  • Beginner
  • *
  • Posts: 31
Re: Ratings in category view
« Reply #3 on: June 21, 2012, 05:04:18 am »
I found this section in the forum that worked except for one issue, when I rated one product is shows on all of them.

http://forum.virtuemart.net/index.php?topic=97611.msg346642#msg346642

If you can figure this issue out or if anyone can help resolve this issue, I would be grateful!

Thanks in advance! 8)

dodgyjammer

  • Beginner
  • *
  • Posts: 5
Re: Ratings in category view
« Reply #4 on: July 05, 2012, 17:06:20 pm »
Hi guys, hope I'm not too late!

To pull back individual product ratings for each product in category view you need to edit com_virtuemart/views/category/view.html.php

Around line 142 you need to change...

Code: [Select]
foreach($products as $product)
{
$product->stock = $productModel->getStockIndicator($product);
}

to...

Code: [Select]
$ratingModel = VmModel::getModel('ratings');
       
foreach($products as $product)
{
$product->stock = $productModel->getStockIndicator($product);
        $product->showRating = $ratingModel->showRating($product->virtuemart_product_id);
        if ($product->showRating)
        {
              $product->vote = $ratingModel->getVoteByProduct($product->virtuemart_product_id);
              $product->rating = $ratingModel->getRatingByProduct($product->virtuemart_product_id);
        }
}

THEN you add the following where you want to show the stars for each product (com_virtuemart/views/category/tmpl/default.php)...

Code: [Select]
<?php if($product->showRating): ?>
    <?php $maxrating VmConfig::get('vm_maximum_rating_scale'5); ?>
    <?php if (!empty($product->rating)):
        
$ratingwidth = ( $product->rating->rating 100 ) / $maxrating?>

        <span class="vote">
            <?php echo JText::_('COM_VIRTUEMART_RATING') . ' ' round($product->rating->rating2) . '/' $maxrating?><br/>
            <span title=" <?php echo (JText::_("COM_VIRTUEMART_RATING_TITLE") . $product->rating->rating '/' $maxrating?>" class="vmicon ratingbox" style="display:inline-block;">
                <span class="stars-orange" style="width:<?php echo $ratingwidth.'%'?>"></span>
            </span>
        </span>
        <br/><br/>
    <?php endif ?>
<?php endif ?>

bingo bango bongo

Sonictech

  • Beginner
  • *
  • Posts: 31
Ratings in category view
« Reply #5 on: July 06, 2012, 00:20:57 am »
Thanks for the help but I switch to Hikashop.  Works good and excellent support.

srajca

  • Jr. Member
  • **
  • Posts: 146
Re: Ratings in category view
« Reply #6 on: July 06, 2012, 22:16:05 pm »
thanks to dodgyjammer I have this working now.
I am also pasting here the code so that it shows text if the product hasn't been rated yet. Just in case somebody else wants it.
Code: [Select]
if ($product->showRating) {
    $maxrating = VmConfig::get('vm_maximum_rating_scale', 5);

    if (empty($product->rating)) {
?>
<span class="vote"><?php echo JText::_('COM_VIRTUEMART_RATING') . ' ' JText::_('COM_VIRTUEMART_UNRATED'?></span>
    <?php
} else {
    $ratingwidth = ( $product->rating->rating 100 ) / $maxrating//I don't use round as percetntage with works perfect, as for me
    ?>

<span class="vote">
<?php echo JText::_('COM_VIRTUEMART_RATING') . ' ' round($product->rating->rating2) . '/' $maxrating?><br/>
    <span title=" <?php echo (JText::_("COM_VIRTUEMART_RATING_TITLE") . $product->rating->rating '/' $maxrating?>" class="vmicon ratingbox" style="display:inline-block;">
<span class="stars-orange" style="width:<?php echo $ratingwidth.'%'?>">
</span>
    </span>
</span>
<?php
    }
}?>
thanks again dodgyjammer