VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: camble on August 14, 2014, 12:37:46 PM

Title: Ratings (stars) on category view and in featured products module
Post by: camble on August 14, 2014, 12:37:46 PM
I am running Joomla 2.5.20 and VM 2.6.6.


I am currently working on a new site and I want the ratings (stars) to appear on the category page for each product. I also want it to appear for featured products on the homepage.

I have used this (reply #4) http://forum.virtuemart.net/index.php?topic=101181.0 (http://forum.virtuemart.net/index.php?topic=101181.0) on the featured products on the homepage and it's working great, however I wondered whether it's possible to show a "not rated yet" graphic/message for products that haven't got a rating yet rather than nothing appear?

The dev site is http://www.netfuel.co.uk/dev/kartsandparts/


The code I am using in the mod_virtuemart_product mod_virtuemart_product.php file is:
------------------------------------------------------------------------------------------------

   $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);
         }
   }

------------------------------------------------------------------------------------------------


The code I am using in the mod_virtuemart_product default.php file is:
------------------------------------------------------------------------------------------------

            <?php $maxrating = VmConfig::get('vm_maximum_rating_scale', 5); ?>
               <?php

               if (!empty($product->rating)):
                  $ratingwidth = ( $product->rating->rating * 100 ) / $maxrating; ?>
                  <span class="rating">
                     <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 endif ?>

------------------------------------------------------------------------------------------------




Kind regards
Liam
Title: Re: Ratings (stars) on category view and in featured products module
Post by: seyi on August 14, 2014, 13:28:47 PM
Seems you could add an else statement:

              <?php

               
if (!empty($product->rating)):
                  
$ratingwidth = ( $product->rating->rating 100 ) / $maxrating?>

                  <span class="rating">
                     <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 else ?>
                  <span>not rated yet </span>
               <?php endif ?>
Title: Re: Ratings (stars) on category view and in featured products module
Post by: camble on August 14, 2014, 14:06:02 PM
Thank you for the prompt response Seyi.

Unfortunately when I put the code in it seemed to error and just threw up a blank page...?


Kind regards
Liam
Title: Re: Ratings (stars) on category view and in featured products module
Post by: seyi on August 14, 2014, 14:16:31 PM
Ah yes,  change

<?php else ?>

to

<?php else: ?>

It needs a colon
Title: Re: Ratings (stars) on category view and in featured products module
Post by: camble on August 14, 2014, 21:45:34 PM
That worked perfectly, thank you very much.
Title: Re: Ratings (stars) on category view and in featured products module
Post by: GJC Web Design on August 14, 2014, 22:33:21 PM
perfect reason to use curly braces - hate the colon notation ... text editors never "read" the syntax