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
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 ?>
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
Ah yes, change
<?php else ?>
to
<?php else: ?>
It needs a colon
That worked perfectly, thank you very much.
perfect reason to use curly braces - hate the colon notation ... text editors never "read" the syntax