Author Topic: Ratings (stars) on category view and in featured products module  (Read 2713 times)

camble

  • Beginner
  • *
  • Posts: 34
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 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

seyi

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 407
    • AwoDev
Re: Ratings (stars) on category view and in featured products module
« Reply #1 on: August 14, 2014, 13:28:47 pm »
Seems you could add an else statement:
Code: [Select]
              <?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 ?>
Seyi A
--------------------
Promotion enhancement for Virtuemart:
   - AwoCoupon FREE - http://www.awocoupon.com/starter
   - AwoCoupon Pro - http://awodev.com/products/joomla/awocoupon
   - AwoRewards - http://awodev.com/products/joomla/aworewards
   - AwoAffiliate - http://awodev.com/products/joomla/awoaffiliate

camble

  • Beginner
  • *
  • Posts: 34
Re: Ratings (stars) on category view and in featured products module
« Reply #2 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

seyi

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 407
    • AwoDev
Re: Ratings (stars) on category view and in featured products module
« Reply #3 on: August 14, 2014, 14:16:31 pm »
Ah yes,  change

<?php else ?>

to

<?php else: ?>

It needs a colon
Seyi A
--------------------
Promotion enhancement for Virtuemart:
   - AwoCoupon FREE - http://www.awocoupon.com/starter
   - AwoCoupon Pro - http://awodev.com/products/joomla/awocoupon
   - AwoRewards - http://awodev.com/products/joomla/aworewards
   - AwoAffiliate - http://awodev.com/products/joomla/awoaffiliate

camble

  • Beginner
  • *
  • Posts: 34
Re: Ratings (stars) on category view and in featured products module
« Reply #4 on: August 14, 2014, 21:45:34 pm »
That worked perfectly, thank you very much.

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10637
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.8.8
Re: Ratings (stars) on category view and in featured products module
« Reply #5 on: August 14, 2014, 22:33:21 pm »
perfect reason to use curly braces - hate the colon notation ... text editors never "read" the syntax
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation