【问题标题】:How can I get the review count on review's list.phtml in Magento 1.8?如何获得 Magento 1.8 中评论 list.phtml 的评论计数?
【发布时间】:2014-07-09 13:30:38
【问题描述】:

如何获取评论的 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 的计数将始终返回empty

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

知道为什么吗?

我的 catalog.xml 的 &lt;catalog_product_view translate="label"&gt; 中有代码,

           <!-- 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 -->

【问题讨论】:

  • $summaryData->getReviewsCount() 或 $summaryData->getData('reviews_count') 有效吗?
  • 另外,你从哪里得到 $_product->getId() 因为我没有在你的代码中看到产品模型? “getId()”错误是因为没有产品型号。试试这个,把这段代码放在 "$_storeID = ..." $_product = Mage::registry('current_product'); 之前或之下
  • 我应该这样做以获得评论计数&lt;?php $_helper = $this-&gt;helper('catalog/output'); ?&gt; &lt;?php $_product = $this-&gt;getProduct(); ?&gt; &lt;?php $storeId = Mage::app()-&gt;getStore()-&gt;getId(); $summaryData = Mage::getModel('review/review_summary')-&gt;setStoreId($storeId)-&gt;load($_product-&gt;getId()); //var_dump($summaryData['reviews_count']); ?&gt;
  • 感谢您的回答和提示! :D

标签: php magento magento-1.8


【解决方案1】:

请尝试非常简单的代码它对我有用。

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

看起来像附上的截图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-02
    • 1970-01-01
    • 2014-03-23
    • 2011-03-21
    • 2022-01-27
    • 2016-03-21
    • 2019-02-18
    • 1970-01-01
    相关资源
    最近更新 更多