Author Topic: Virtuemart Ratingcount Bug (does not update correctly)  (Read 521 times)


  • Beginner
  • *
  • Posts: 10
  • A beginner
  • VirtueMart Version: 3.6.8 (v.10197) on Joomla! 3.9.13
Virtuemart Ratingcount Bug (does not update correctly)
« on: October 17, 2018, 23:52:57 pm »
The VM system works correctly but has a defect (I do not know if it is actually a bug or a choice):
VM uses 3 different tables to record reviews this because you can enter a vote without writing anything, therefore we find ourselves a table for the votes, one for the reviews and one of "association" between the first and the second that links the vote to the eventual text.
In the table #_virtuemart_ratings (that of the votes), at the moment of the insertion of a review or a vote, the reference string is created for the product, and this is updated every time a new one is inserted.
The official problem is that the "ratingcount" field (the one that is extracted to indicate the number of reviews / votes present) does not update correctly,
therefore instead of adding to the present number a "+ 1" overwrites the field leaving unchanged therefore always to "1".
Basically it is as if there were only a review.
To solve, I inserted in the json code a script that counts all the reviews related to the product in question, then generating the snippet.
In this way we get a precise result that is correctly interpreted by Google Microdata without errors
Officially the problem is solved, but I must remember to integrate this change every time my theme is updated.
The integration is to be done on the file templates / your_template / html / com_virtuemart / sublayouts / snippets.php and now knowing how to do it, it's a very quick change.

The snipped.php modified file, is this:

Code: [Select]
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
$product $viewData['product'];
$currency $viewData['currency'];
$view vRequest::getCmd('view');
$ratingModel VmModel::getModel('Ratings');
$productrating $ratingModel->getRatingByProduct($product->virtuemart_product_id);
$productratingcount = isset($productrating->ratingcount) ? $productrating->ratingcount:'';

/*Recovery Review's ID*/

$tot_recensioni $ratingModel->ids;


I sum up all the reviews present and print them in the snippet



if (
$product->product_in_stock 0)
$availability '';
$availability '';


 echo '<pre>';
 echo '</pre>';


<script type="application/ld+json">
  "@context": "",
  "@type": "Product",
  "name": "<?php echo htmlspecialchars($product->product_name); ?>",
  <?php if ( $product->images[0]->virtuemart_media_id 0) { ?>
  "image": "<?php echo JURI::root().$product->images[0]->file_url?>",
  <?php ?>
  <?php if (!empty($product->product_s_desc)) { ?>
  "description": "<?php echo htmlspecialchars(strip_tags($product->product_s_desc)); ?>",
  <?php } elseif (!empty($product->product_desc)) { ?>
  "description": "<?php echo htmlspecialchars(strip_tags($product->product_desc)); ?>",
  <?php ?>
  <?php if ($viewData['showRating'] && !empty($product->rating)) { ?>
    "@type": "AggregateRating",
    "ratingValue": "<?php echo $product->rating?>",
    "reviewCount": "<?php echo count($tot_recensioni); ?>",
    "@type": "Product",
    "name": "<?php echo htmlspecialchars($product->product_name); ?>"

  <?php ?>
    "@type": "Offer",
    "priceCurrency": "<?php echo $currency->_vendorCurrency_code_3?>",
    "price": "<?php echo round($product->prices['salesPrice'],2); ?>",
    "itemCondition": "",
    "Availability": "<?php echo $availability?>"