1

How can I get the review count on review's list.phtml?

frontend\base\default\template\review/product/view/list.phtml

I get an error when I use this code in this page,

<?php
// Get the number of reviews of the product on the product page.
$storeId    = Mage::app()->getStore()->getId();

$summaryData = Mage::getModel('review/review_summary')
->setStoreId($storeId)
->load($_product->getId());

/* @var $summaryData Mage_Review_Model_Review_Summary */

/*

array(
['primary_id'] => 147
['entity_pk_value'] => 166
['entity_type'] => 1
['reviews_count'] => 1
['rating_summary'] => 80
['store_id'] => 1
)
*/
//var_dump($summaryData['reviews_count']);
?>

error,

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

While the count on frontend\base\default\template\review/product/view/count.phtml will always return empty

<?php if (!empty($count)):?>
    <a href="#customer-reviews" class="nobr"><?php echo $this->__('%s Review(s)', $count) ?></a>
<?php endif;?>

Any idea why?

I have code in my catalog.xml's <catalog_product_view translate="label">,

           <!-- adding review to the product page -->
            <block type="page/html_pager" name="product_review_list.toolbar">
                <action method="setLimit"><limit>2</limit></action>
            </block>
            <block type="review/product_view_list" name="product.info.product_additional_data" as="product_review" template="review/product/view/list.phtml">
                <block type="core/template" name="product_review_list.count" template="review/product/view/count.phtml" />
                <block type="review/form" name="product.review.form" as="review_form"/>
            </block>
            <!-- adding review to the product page -->
4

The error that you are seeing about getId is because there is no object for $_product, the block Mage_Review_Block_Product_View_List has a function getProductId so you should be able to update your code as follows.

$summaryData = Mage::getModel('review/review_summary')
    ->setStoreId($storeId)
    ->load($this->getProductId());
4

Please try very simple code It's work for me.

<?php echo $this->getReviewsSummaryHtml($_product, 'short')?>

It's look like attached screenshot.enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.