Average customer rating not showing up on Category page on every template

Started by MAD King, June 18, 2013, 02:37:11 AM

Previous topic - Next topic

bunglehaze

I will take the code out for the time being maxim, when you are back online please let me know in here and I will add it back for you to look at

Maxim Pishnyak

Ok, I'm back. You could pm me access and I could look into this myself.
You can support Community by voting for Project on the JED
https://extensions.joomla.org/extension/virtuemart/#reviews
Join us at
https://twitter.com/virtuemart

T.A. Garrison, LLC

As many people have posted, this subject is in a lot of places through Virtuemart and other sources. Like everybody else, I've "yet" to find a solution.

A default installation of Virtuemart shows the little oval image with varying colors indicating the rating for the product.
Now that I have edited my template to be fully responsive, the little images no longer work and all I see next to the products is the "Average Customer Rating" text.

http://ltcreations.com/spalena/shopping

I've seen hacks and a lot of talk, but nothing that indicates why in the world the images suddenly no longer appear. Even in this post there is "indication" that there "might" be a resolve. But there is nothing.

Debug shows nothing.
It seems to me that there is something to do with jQuery.
I have a small component that is used for login in order to eliminate the large fields from most horizontal login.
That script has a problem with jQuery in that if the jQuery within Virtuemart is disabled, the login works in Virtuemart. Otherwise, it won't work.
The same issue happened in all the other pages, but the developer made an adjustment and got it to work on the pages that are not part of Virtuemart.

That same developer mentioned that Joomla! 3.5 may have a new method of calling jQuery since there are so many conflicts with the various components trying to use jQuery and all are calling it differently.

I have no idea if this could help, but according to the login script developer, the following script should be used to replace the conflicts with calling jQuery:

$doc = JFactory :: getDocument();
if (version_compare(JVERSION,'3','ge')) {

JHtml::_('jquery.framework');

} else {

if(JFactory::getApplication()->get('jquery') !== true) {
$doc->addScript(JURI::root(true) . 'PATH_TO/jquery.js');
$doc->addScript( JURI::root(true) .'PATH_TO/noconflict.js');
JFactory::getApplication()->set('jquery', true);
}
}

The above will ensure that jQuery is detected in all the different ways it can be loaded in the Joomla Enviroment and then load conditionally. (That's his note and I have no idea if that's true.)

Is it possible the the smart people who develop Virtuemart can review that code and see if it makes sense to use that? It's suggested to place that in the default file of the template.

Another option suggested was to use jQueryEasy.
I used that on another project and it seemed to help. But I haven't tried it on this project.

The bottom line is this.
There are other components in every Joomla! project besides Virtuemart. The template alone causes conflicts. The developer has a point. Why can't there be some "default" method of detecting and calling jQuery?

I would "bet" that "when" this Virtuemart rating issue is resolved, there will be a jQuery conflict at the heart of the issue.
But for now, I would at least like to hear from Virtuemart "HOW" to resolve the fact that the oval images worked at install, but now they do not.
The stars work when I rate something - but not the little images showing the various levels of rating.

I know...the first thing everybody wants to do is say "It worked at default, so it's not Virtuemart."
That's not really resolving anything.
I also know that I'll be asked if I tried the Joomla! default template, like Bees20 or something. Yes, I did switch to one of those and there was no change in the average customer rating text that appears everywhere now.
I've even tried to look using Firebug, but that's no help when there is no code in the text. In other words, the text is just text. There is nothing like broken code looking for an image.

I would love to find a solution and be happy to share it with everybody. Can someone help me do that?

Thanks.
T.A. Garrison, LLC
3150 Orleans St. # 28261
Bellingham, WA 98228

harut2005

Did you found any solution for this issue?
I've tried different methods and tricks but I end up to these:
Using this code
<!-- 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;

}?>

I managed to print the average customer rating in Category.
But this works correctly only if there is only 1 item in category. Because if there is more than 1, then all products get last product's rating !!!

harut2005

This is impossible!!!
I was looking for a solution for hours now, and I just managed to make it work properly for all products in category! 5' after I make the post above  :P

Well, if you are looking for a trick to get all products ratings correctly in Category do the following:
in file: /components/com_virtuemart/views/category/view.html.php
change:
foreach($products as $product){
              $product->stock = $productModel->getStockIndicator($product);
         }

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

with this:
/*  The "Average Customer Rating for all products in category" by harut2005 */

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

foreach($products as $product){
$product->stock = $productModel->getStockIndicator($product);
$product->rating = $ratingModel->getRatingByProduct($product->virtuemart_product_id);
$this->assignRef('rating', $rating);
}


And if you use Vapro's code with a some little changes ( product-> instead of this-> ), everything seems to work now!!!  8)

In file: /components/com_virtuemart/views/category/tmpl/default.php
Change:

<!-- The "Average Customer Rating" Part -->
<?php if ($this->showRating) { ?>
<span class="contentpagetitle"><?php echo JText::('COM_VIRTUEMART_CUSTOMER_RATING'?>:</span>
<br/>
<?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;
?>

<?php ?>


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

}?>