Magento – Fix Review Count Breaking Independent Product Review Page

product-viewreview

Any ideas on what could cause the independent product review page to break when the below code is added to the app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/catalog/product/view.phtml page?

<?php  
  $reviewcount     = $_product->getRatingSummary()->getReviewsCount(); 
  $this->getLayout()->getBlock('product.info.tabs')->setReviewCount($reviewcount); ?>

I'm running Magento 1.7.0.2. I have successfully used the above code to get the review count number to display in a tab in the product view page. The problem is when a user clicks the default product review link the page will not load anything past the above code on the product review page. Does anyone have any ideas on a way to overcome this issue?

Just FYI I have followed this tutorial to achieve adding the review count to a custom product review tab and this is where the above code originated from: http://www.magentocommerce.com/boards/v/viewthread/237020/

Best Answer

Not sure why this is, but I found that by including this <?php $_product = Mage::registry('product'); ?> above the code mentioned in the question. I was able to get it to work. I also moved all the code to it's own .phtml file so that it would only be included on the product view page by adding a couple lines to the local.xml Like so.

<catalog_product_view translate="label">
     <reference name="product.info">
        <block type="core/template" name="reviewCountTabBlock" template="catalog/product/view/tabs/review_count.phtml" />
    </reference>
</catalog_product_view>

Then on the view.phtml I added this:

    <?php echo $this->getChildHtml('reviewCountTabBlock') ?>

and in the new template catalog/product/view/tabs/review_count.phtml I added this:

    <?php $_product = Mage::registry('product'); ?>
<?php 
    // Add this code to get review count
    //$summary         = $this->getReviewsSummaryHtml($_product, false, true); 
    $reviewcount     = $_product->getRatingSummary()->getReviewsCount(); 
    $this->getLayout()->getBlock('product.info.tabs')->setReviewCount($reviewcount);
?>

And that cleaned everything up. I hope this helps others.

Related Topic