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

Ratings (stars) on category view and in featured products module

Started by camble, August 14, 2014, 12:37:46 PM

Previous topic - Next topic

camble

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

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 ?>
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

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

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


GJC Web Design

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
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 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