• Page:
  • 1

Show Ratings in Virtuemart Category Page

OFFLINE

Show Ratings in Virtuemart Category Page

6 years, 6 months ago
Hi Guys,

This is also very simple actually.
Open your category page view.html.php file and find for this code
foreach($products as $product)
{
	$product->stock = $productModel->getStockIndicator($product);
}

Replace this with this:
$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);
        }
}


Then add the following in your default.php file:

<?php
            if ($this->showRating) {
                $maxrating = VmConfig::get ('vm_maximum_rating_scale', 5); // these are imp
                $ratingsShow = VmConfig::get ('vm_num_ratings_show', 3); // these are imp
                if (empty($product->rating)) {
            ?>
            <span class="vote"><?php echo JText::_('COM_VIRTUEMART_RATING') . ' ' . JText::_('COM_VIRTUEMART_UNRATED') ?></span>
            <?php
        } else {
            $ratingwidth = ( $product->rating->rating * 100 ) / $maxrating; 
            ?>
            <span class="vote">
	<?php echo JText::_('COM_VIRTUEMART_RATING') . ' ' . round($product->rating->rating, 2) . '/' . $maxrating; ?><br/>
			    <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
        }
    }?>




Thanks!
Last Edit: 6 years, 6 months ago by Deepesh Chang.
The following user(s) said Thank You: Vicky Jain, Arihant Jain
OFFLINE

Re: Show Ratings in Virtuemart Category Page

3 years, 11 months ago
In VM 3.0 You just need to enable it from the backend..
The following user(s) said Thank You: Vicky Jain, Krunal Nanda
  • Page:
  • 1

Upcoming Events

Who's Online

3 users online