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
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); }
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