News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Ratings in category view

Started by Bruce Morgan, April 13, 2012, 02:05:27 AM

Previous topic - Next topic

Bruce Morgan

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


Rixters

Same here... Noticed that in the PHP file from catergory layout this part in disabled... Enabling it gives the following:

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


Maybe some more work needs te be done here..

Sonictech

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

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...


foreach($products as $product)
{
$product->stock = $productModel->getStockIndicator($product);
}


to...


$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)...


<?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

Thanks for the help but I switch to Hikashop.  Works good and excellent support.

srajca

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.
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