cancel
Showing results for 
Search instead for 
Did you mean: 

Fatal error: Call to a member function getReviewsCount() on a non-object

Fatal error: Call to a member function getReviewsCount() on a non-object

 

Hi Guys and Girls

 

I'm having a roblem with a code snippet.

 

I'm running magento 1.9.01 on php 5.5.

 

I'm trying to hide my Review-tab on product page IF there is no reviews. I'm currently using this snippet below.

 

<?php 

   $reviewCount = $_product != null && $_product->getRatingSummary()->getReviewsCount() ? $_product->getRatingSummary()->getReviewsCount() : 0;
    if($reviewCount === 0){
    	echo '<style>#tab-tabreviews, h2#acctab-tabreviews.acctab {visiblity:hidden;display:none;}</style>';} ?>

 

It works like a charm on the product page, but it returns

Fatal error: Call to a member function getReviewsCount() on a non-object

on the products review page.

 

Any of you smart people know how to fix this issue?

 

Thx in advance

Best regards Tom

 

2 REPLIES 2

Re: Fatal error: Call to a member function getReviewsCount() on a non-object

@MrToms77

Check this code out. It will fix the issue.

/**
* Getting reviews collection object
*/
$productId = $product->getId();
$reviews = Mage::getModel('review/review')
->getResourceCollection()
->addStoreFilter(Mage::app()->getStore()->getId()) 
->addEntityFilter('product', $productId)
->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
->setDateOrder()
->addRateVotes();
/**
* Getting average of ratings/reviews
*/
$avg = 0;
$ratings = array();
if (count($reviews) > 0) {
foreach ($reviews->getItems() as $review) {
foreach( $review->getRatingVotes() as $vote ) {
$ratings[] = $vote->getPercent();
}
}
$avg = array_sum($ratings)/count($ratings);
}
Was my answer helpful? You can accept it as a solution.
175+ Professional Extensions for M1 & M2
Need a developer?Just visit Contact Us Now

Fatal error: Class 'Mage_Core_Helper_Data' not found in xxxx /app/Mage.php on line 547

Hi All,

 

I'm getting the response like that and am new to magento CE. can someone help me to resolve the same.

 

 

Fatal error: Class 'Mage_Core_Helper_Data' not found in /home/kiruba/public_html/app/Mage.php on line 547