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

Rating Images not showing up

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

Previous topic - Next topic

tobisagt

#15
thx hollywood,

i modified your code a bit. I think this makes more sense!

if ($this->rating->rating < "0.25"){
echo '<div class="rating "zero"></div>';
}

if ($this->rating->rating >= "0.25" & $this->rating->rating < "0.75"){
echo '<div class="rating zerofive"></div>';
}

if ($this->rating->rating >= "0.75" & $this->rating->rating < "1.25"){
echo '<div class="rating one"></div>';
}

if ($this->rating->rating >= "1.25" & $this->rating->rating < "1.75"){
echo '<div class="rating onefive"></div>';
}

if ($this->rating->rating >= "1.75" & $this->rating->rating < "2.25"){
echo '<div class="rating two"></div>';
}

if ($this->rating->rating >= "2.25" & $this->rating->rating < "2.75"){
echo '<div class="rating twofive"></div>';
}

if ($this->rating->rating >= "2.75" & $this->rating->rating < "3.25"){
echo '<div class="rating three"></div>';
}

if ($this->rating->rating >= "3.25" & $this->rating->rating < "3.75"){
echo '<div class="rating threefive"></div>';
}

if ($this->rating->rating >= "3.75" & $this->rating->rating < "4.25"){
echo '<div class="rating four"></div>';
}

if ($this->rating->rating >= "4.25" & $this->rating->rating < "4.75"){
echo '<div class="rating fourfive"></div>';
}

if ($this->rating->rating >= "4.75" & $this->rating->rating <= "5"){
echo '<div class="rating five"></div>';
}


I've made my own stars images which shows half stars also.
Your solution works only if there a "full number" vote, if you know what i mean. If there is a 2 stars and 3 stars vote, it should show 2,5 stars.

I uploaded my stars jpg too, if someone want to use it.


EDIT: I updated to Joomla 2.5 and VM 2.0.2. All works fine now!

[attachment cleanup by admin]

vapro

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;

}?>

hollywooood

Hi Electricity...

Couldn't you add the extra if statements for the extra ratings or change it as you need?  Maybe I am unclear on what you are suggesting.

Glad I could at least get the ball rolling on this problem.  Nice work vapro...

Joomla 2.5.4
Virtuemart 2.0.6
PHP 5.2.17
MySQL 5.5.21-55
APACHE 2.2.22

sandstorm

Ive now upgraded to J2.5.1, VM 2.02 and still this problem persists. I have tried with default templates, both Joomla and virtuemart.

Can anyone on the VM dev team comment if this is a bug or not?

I will look at Vapro's fix, but worried that this will be overwritten when another upgrade comes out ?

Andy
J3.6.4 / PHP7.0.12
VM3.0.16

sandstorm

I only just notice after reading VAPRO's comments.
I cant get my ratings to show in details page.

The modified code in VAPRO's post is for category view
J3.6.4 / PHP7.0.12
VM3.0.16

sandstorm

problem persists? 
Anybody else see this in there sites? or have any advice for me
J3.6.4 / PHP7.0.12
VM3.0.16

hollywooood

Hey tobisagt, what does your css look like for this?  I just migrated to 2.5 and 2.0.2 and need to add this in...

thanks for any help on that...
Joomla 2.5.4
Virtuemart 2.0.6
PHP 5.2.17
MySQL 5.5.21-55
APACHE 2.2.22

fexnok

Where can I find those images? I have just downloaded virtuemart 2.0.2 and I couldn't find them.

Thanks

jenkinhill

The image is in joomla_root/components/com_virtuemart/assets/images/color-stars.png

Display of the review rating image is dependant on the Joomla template and that templates's css. The attached is the display in one of the Linelab templates.

[attachment cleanup by admin]
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

hollywooood

#24
Somethings are waay more easier than we make them out to be...

For those who don't know on this and are making a custom template here is what you may need to do if you are using your own css.

Make sure you copy & paste these lines in your style sheet from virtuemart-ltr.css:
.ratingbox {
position:relative;
display:block;
width:120px;
height:24px;
background:url("pathto/images/color-stars.png") repeat-x scroll 0 bottom transparent;
}
.ratingbox span {
background:url(pathto/images/color-stars.png) repeat-x;
display:block;
width:1%;
height:24px;
position:absolute;
}
.stars-orange{background-position:0 0 !important;}
.stars-red{background-position:0 -54px !important;}
.stars-green{background-position:0 -108px !important; }
.stars-blue{background-position:0 -162px !important;}
.stars-purple{background-position:0 -216px !important;}


You will need this somewhere in your productdetails default.php page:

<?php
if ($this->showRating) {
    $maxrating VmConfig::get('vm_maximum_rating_scale',5);

if (empty($this->rating)) { ?>

<span class="vote"><?php echo JText::_('COM_VIRTUEMART_RATING').' '.JText::_('COM_VIRTUEMART_UNRATED'?></span>
<?php } else {
$ratingwidth = ( $this->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($this->rating->rating2) . '/'$maxrating?><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
}
}
?>


You'll notice that it not only takes care of the rated image, it will also handle the JS review and ratings display..

it really is that easy...the main thing was that I missed the css for this and that is what really gave me a headache...I was overthinking it way too much.
Joomla 2.5.4
Virtuemart 2.0.6
PHP 5.2.17
MySQL 5.5.21-55
APACHE 2.2.22

DaggaTora

This is great guys but... what about to hide rating if the product has not been review?
Joomla 2.5.17 | VM2.0.26d | PHP 5.3.28

DaggaTora

I just delete <span class="vote"><?php echo JText::_('COM_VIRTUEMART_RATING').' '.JText::_('COM_VIRTUEMART_UNRATED') ?> hope it works!  ;D
Joomla 2.5.17 | VM2.0.26d | PHP 5.3.28

Sonictech

Quote from: DaggaTora on June 19, 2012, 19:05:22 PM
I just delete <span class="vote"><?php echo JText::_('COM_VIRTUEMART_RATING').' '.JText::_('COM_VIRTUEMART_UNRATED') ?> hope it works!  ;D

Where you able to solve this, did this work by deleting  line you listed above?  I have followed the instructions so far and I see the ratings in the category area but the only issue it shows the same rating on all products even if they have not been rated yet.  I tried removing the line above but it did not work, any other idea?

Thanks for any help! 8)

DaggaTora

This is what i did to have stars when someone voted and to shows nothing when nobody has vote:

<?php
if ($this->showRating) {
    $maxrating VmConfig::get('vm_maximum_rating_scale',5);

if (empty($this->rating)) { ?>

<span class="vote" style="display:none"><?php echo JText::_('COM_VIRTUEMART_RATING').' '.JText::_('COM_VIRTUEMART_UNRATED'?></span>

<?php } else {
$ratingwidth = ( $this->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($this->rating->rating2) . '/'$maxrating?><br/>-->
<span title=" <?php echo (JText::_("COM_VIRTUEMART_RATING_TITLE") . $this->rating->rating '/' $maxrating?>" class="ratingbox" style="display:inline-block;">
<span class="stars-orange" style="width:<?php echo $ratingwidth;?>%">
</span>
</span>
</span>
<?php
}
}
?>


Hope it helps!
Joomla 2.5.17 | VM2.0.26d | PHP 5.3.28

Sonictech

I put the code in the category/default.php and have added a couple of stars to a product, no luck.  I then put back the original code and I see the stars but none of them are gold color, any idea?

Thanks,
Shawn