簡體   English   中英

如何在Magento 1.8中獲取評論的list.phtml的評論數?

[英]How can I get the review count on review's list.phtml in Magento 1.8?

如何獲得評論的list.phtml的評論數?

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

在此頁面中使用此代碼時出現錯誤,

<?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']);
?>

錯誤,

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

雖然frontend\\base\\default\\template\\review/product/view/count.phtml上的計數將始終返回

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

知道為什么嗎?

我的catalog.xml的<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 -->

請嘗試非常簡單的代碼,這對我來說很有效。

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

看起來就像所附的屏幕截圖。 在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM