Review Count Added to a Product Tab that Contains Reviews: Breaks the Independent Product Review Page

magento.stackexchange https://magento.stackexchange.com//questions/38552

  •  12-12-2019
  •  | 
  •  

Question

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/

Was it helpful?

Solution

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.

OTHER TIPS

This is a quick solution on Magento 1.9:

in catalog/product/view.phtml

on this part:

<?php if ($detailedInfoGroup = $this->getChildGroup('detailed_info', 'getChildHtml')):?>
        <dl id="collateral-tabs" class="collateral-tabs">
            <?php foreach ($detailedInfoGroup as $alias => $html):?>
                <dt class="tab">
                    <span><?php echo $this->escapeHtml($this->getChildData($alias, 'title')); ?></span>
                </dt>
                <dd class="tab-container">
                    <div class="tab-content"><?php echo $html ?></div>
                </dd>
            <?php endforeach;?>
        </dl>
    <?php endif; ?>

Change it to become like this:

      <?php if ($detailedInfoGroup = $this->getChildGroup('detailed_info', 'getChildHtml')):?>
            <dl id="collateral-tabs" class="collateral-tabs">
                <?php foreach ($detailedInfoGroup as $alias => $html):?>
                    <?php $tabTitle = $this->escapeHtml($this->getChildData($alias, 'title')); ?>
                    <?php $reviewsCount = Mage::app()->getLayout()->createBlock('review/product_view')->getReviewsCollection()->getSize(); ?>
                    <dt class="tab">
                        <span><?php echo strtolower($tabTitle) == 'reviews' && $reviewsCount
            ? $this->__('Reviews %s', '(' . $reviewsCount . ')') : $tabTitle; ?></span>
                    </dt>
                    <dd class="tab-container">
                        <div class="tab-content"><?php echo $html ?></div>
                    </dd>
                <?php endforeach;?>
            </dl>
        <?php endif; ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top