VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: fapi2 on October 17, 2018, 23:52:57 PM

Title: Virtuemart Ratingcount Bug (does not update correctly)
Post by: fapi2 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:


<?php
// 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');
if(
$viewData['showRating']){
$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 'http://schema.org/InStock';
   }
   else
   
$availability 'http://schema.org/OutOfStock';

/*

 echo '<pre>';
print_r($product);
 echo '</pre>';

 */
?>


<script type="application/ld+json">
{
  "@context": "http://schema.org/",
  "@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)) { ?>
  "aggregateRating":{
    "@type": "AggregateRating",
    "ratingValue": "<?php echo $product->rating?>",
    "reviewCount": "<?php echo count($tot_recensioni); ?>",
     "itemReviewed":{
    "@type": "Product",
    "name": "<?php echo htmlspecialchars($product->product_name); ?>"
    }
  },

  <?php ?>
  "offers":{
    "@type": "Offer",
    "priceCurrency": "<?php echo $currency->_vendorCurrency_code_3?>",
    "price": "<?php echo round($product->prices['salesPrice'],2); ?>",
    "itemCondition": "http://schema.org/NewCondition",
    "Availability": "<?php echo $availability?>"
  }
}
</script>


Title: Re: Virtuemart Ratingcount Bug (does not update correctly)
Post by: Tempe on November 08, 2021, 18:56:00 PM
Hi there,
I know this is old, but I am having exactly this issue, is this fix still valid?
Joomla 3.10.3
Virtuemart 3.8.8 10472
PHP Version 7.4.25
I have tried 2 different virtuemart templates and the rating count is still only ever 1.
If I need to open a new topic for this same issue I will do, but I thought I'd ask on this thread as it's the same issue.
TIA
Title: Re: Virtuemart Ratingcount Bug (does not update correctly)
Post by: mortenjensen on November 08, 2021, 22:45:26 PM
I'm having the exact same issue and I'm on the same Joomla version (at the time of writing ‎3.10.3).

The fix looks promising. I'll try it.
Title: Re: Virtuemart Ratingcount Bug (does not update correctly)
Post by: GJC Web Design on November 09, 2021, 09:50:06 AM
?  this code has been in components\com_virtuemart\sublayouts\snippets.php for at least a couple of years
Title: Re: Virtuemart Ratingcount Bug (does not update correctly)
Post by: Tempe on November 09, 2021, 14:41:19 PM
The code does not seem to update the rating count in Table: x_virtuemart_ratings. The rating updates in relation to the rating votes, but the rating count always stays at 1, so as far as Google is concerned there is only 1 vote. I have snippets.php copied from virtuemart 3.8.8 in the sublayouts folders of both com_virtuemart core, and the HTML of template folder, is this correct?
TIA