News:

Support the VirtueMart project and become a member

Main Menu

Rating Images not showing up

Started by sandstorm, February 06, 2012, 16:18:24 PM

Previous topic - Next topic

srajca

Hey Sonictech, have you managed to fix this. If I use the code above then every product in the category has the same rating?
Thanks

Sonictech

No not yet, still waiting on some help with this.

Thanks,
Shawn

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

srajca

hmm ... I followed your instructions precisely but I can't seem to get it working. Am I forgetting something, could you post your whole code so I can see where is it at?
Thank you

dodgyjammer

Hi srajca,

Things to check:

  • you have entered a rating/ratings for the products you are viewing in category view. My code won't show anything if there are no ratings there.
  • your site is configured to show ratings to the user in question (Virtuemart backend -> Configuration -> Shopfront -> Show Ratings)
  • you have added the code to show the stars within where individual products are being output i.e. within this foreach loop


foreach ( $this->products as $product ) {


Let me know how you get on.

srajca

ok perfect i got it working, I needed to edit the original file of view.html.php. Is there a way to override this file, so that I don't have to change it every upgrade?
Also how can I show "not yet rated" for products that haven't been rated yet?
Thanks for all the help

srajca

I got it...now I have rating where product has been rated and I also have text, product not yet rated where product doesn't have any rating. I used this code from productdetails and changed all $this variables to $product.
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
    }
}?>

readyforchange

#37
Quote from: vapro on February 26, 2012, 02:09:20 AM
Problem solved.

it was a big bug...


this lines missing from components>com_virtuemart>views>category>view.html.php file:

find:
$ratingModel = VmModel::getModel('ratings');
$showRating = $ratingModel->showRating();
$this->assignRef('showRating', $showRating);


replace:
$ratingModel = VmModel::getModel('ratings');
$showRating = $ratingModel->showRating();
$this->assignRef('showRating', $showRating);

// added lines from  components>com_virtuemart>views>productdetails>view.html.php
$rating = $ratingModel->getRatingByProduct($product->virtuemart_product_id);
$this->assignRef('rating', $rating);


Add this lines where you want to diplay stars: components>com_virtuemart>views>category>tmpl>default.php

<!-- The "Average Customer Rating" Part by Vapro -->
<?php 
                
if($this->showRating){
    $maxrating VmConfig::get('vm_maximum_rating_scale',5);
$rating = empty($this->rating)? JText::_('COM_VIRTUEMART_RATING').' '.JText::_('COM_VIRTUEMART_UNRATED'):JText::_('COM_VIRTUEMART_RATING') . round($this->rating->rating) . '/'$maxrating;
$ratingwidth = ( $this->rating->rating 100 ) / $maxrating;
?>

                    <span class="vote">
<?php echo $rating  ?>
                    <br/>
                        <span title=" <?php echo (JText::_("COM_VIRTUEMART_RATING_TITLE") . $this->rating->rating '/' $maxrating?>" class="vmicon ratingbox" style="display:inline-block;">
                            <span class="stars-orange" style="width:<?php echo $ratingwidth;?>%">
                            </span>
                        </span>
</span>
<?php
//$img_url = JURI::root().VmConfig::get('assets_general_path').'/reviews/'.$product->votes->rating.'.gif';
//echo JHTML::image($img_url, $product->votes->rating.' '.JText::_('COM_VIRTUEMART_REVIEW_STARS'));
//echo JText::_('COM_VIRTUEMART_TOTAL_VOTES').": ". $product->votes->allvotes;

}?>


Hey VAPRO.

Thanks for posting a solution.  Unfortunately it doesn't work for me... i am running vm 2.0.8e / joomla 2.5.6

For some reason I get  "Rating: Not Rated Yet" and I see empty stars.  Even though my review is published.  Any other tips you can give me ?
 

inthysite

Quote from: readyforchange on August 13, 2012, 21:36:09 PM

Hey VAPRO.

Thanks for posting a solution.  Unfortunately it doesn't work for me... i am running vm 2.0.8e / joomla 2.5.6

For some reason I get  "Rating: Not Rated Yet" and I see empty stars.  Even though my review is published.  Any other tips you can give me ?
 

Same here, empty stars and Rating: Not Rated Yet message.  If you click on the product you see the actual rating so I know it is saved.

phobophil

I've got the same problems like inthysite and readyforchange using VAPROs code, empty stars! And now, what can I do?

jenkinhill

You cannot use that code in 2.0.18a - in any case the issue of stars occasionaly not showing was fixed a few VM versions ago.

We do not support hacks to core files.
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

phobophil

#41
Thanks jenkinhill,

Please explain me for a better understanding. Every new version of VM does not contain completely all developed features of the previous version? Maybe I am naive, but I don´t know. I will try to avoid hacking the core files, especially like in this case and with my insufficient knowledge. It´s not that important showing the rating stars in my product list, because they are already on my detailed product page. But nevertheless it would be nice if they are shown.

wess

Are their any updates on the missing Average Customer rating in the product listings. Jenkinhill said it was fixed awhile ago but they are still missing for me and I'm using 2.0.18a

Favazza

#43
Got this site (J2.5.9 & VM2.0.18a) and when a product is rated only 5/5 shows up. No stars?! Is this a template issue?
From the beginning I wanted the stars to show up in category view, but as they don't even show up in product view, I have to solve that first.

Edit: Tried standard templates, but same issues.

Favazza