1. 根据产品id获取该产品评论

$productId = 1234;
$product = Mage::getModel('catalog/product')->load($productId);$storeId = Mage::app()->getStore()->getId();
Mage::getModel('review/review')->getEntitySummary($product, $storeId);$ratingSummary = $product->getRatingSummary();
print_r($ratingSummary->getData());

结果是:

Array
([primary_id] => 27[entity_pk_value] => 16[entity_type] => 1[reviews_count] => 3[rating_summary] => 51[store_id] => 1
)

结果解释如下:

//Entity id of a summary review
["primary_id"] => string(3) "27"
//
//Product id
["entity_pk_value"] => string(3) "16"
//
//Entity type id: 1-Product; 2-Customer; 3-Category
["entity_type"] => string(1) "1"
//
//Qty of reviews
["reviews_count"] => string(1) "3"
//
//Summarized rating: the percentage which represents number of stars, each 20% step fills up one star
["rating_summary"] => string(2) "51"
//
//Store id
["store_id"] => string(1) "1"

或者简单点:

<?php
$storeId    = Mage::app()->getStore()->getId();
$summaryData = Mage::getModel('review/review_summary')->setStoreId($storeId)->load($productId);
if($summaryData->getRatingSummary()){
?><div class="rating-box" style="float:left;"><div class="rating" style="width: <?php echo $summaryData->getRatingSummary().'%'; ?>"></div></div>
<?php  } ?>

2. 获取所有评论

function getReviews() {$reviews = Mage::getModel('review/review')->getResourceCollection();$reviews->addStoreFilter( Mage::app()->getStore()->getId() )->addStatusFilter( Mage_Review_Model_Review::STATUS_APPROVED )->setDateOrder()->addRateVotes()->load();        return $reviews;
}

结合上面的函数,我自己使用的例子如下:

$home_reviews = array();
$storeId      = Mage::app()->getStore()->getId();
$reviews      = Mage::getModel('review/review')->getCollection()->addStoreFilter($storeId)->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)->setPageSize(5)->setCurPage(1)->setDateOrder();foreach($reviews as $key=>$review)
{$home_reviews[$key]           = $review->getData(); $home_reviews[$key]['rating'] = Mage::getModel('review/review_summary')->setStoreId($storeId)->load($review->getEntityPkValue())->getRatingSummary();$home_reviews[$key]['rate']   = number_format($home_reviews[$key]['rating']*5/100,1);
}

这个例子结合了几个条件,1. 状态是 APPROVED   2. 时间排序,最新在前   3. 只获取前五个

原文/转自:Magento: 获取产品评论 get all reviews with review summary

Magento: 获取产品评论 get all reviews with review summary相关推荐

  1. Magento获取产品自定义属性及对应的值

    自定义产品属性后,通常可以设置其是否在产品查看页中显示,可显属性将会出现在additional information 中.但是这边我需要在分类列表页中调用产品特定的属性. 在列表页循环获取对应产品的 ...

  2. magento 获取产品的属性值

    magento采用强大的EAV设计方法,我们可以很方便的给商品添加任意数量的属性,那如何在前台获取这些属性值呢? magento同样提供了很方便的方式来读取它.使用$_product->getA ...

  3. magento -- 获取产品的属性值

    magento采用强大的EAV设计方法,我们可以很方便的给商品添加任意数量的属性,那如何在前台获取这些属性值呢?magento同样提供了很方便的方式来读取它.使用$_product->getAt ...

  4. magento 获取产品存货量以及configurable product 下associated children product信息

    Magento – Get Product Stock Quantity To get the quantity in stock for a particular product in Magent ...

  5. Magento教程 20:仅限会员留言的产品评论设定!

    欢迎使用Magento购物车系统 ,之前和大家说明过为了防止垃圾留言, Magento的产品评论需要管理者审核才可发布. 当有人留言时不会立即显现于前台,而是出现在后台供管理员审核后才会送出. 今天则 ...

  6. Magento 获取有效属性 Display available options for attributes of Configurable

    1. 获取全部 //get Product $cProduct = Mage::getModel('catalog/product')->load($_product->getId()); ...

  7. Magento 批量刷入 Amazon上的产品评论

    网站上线前都需要弄点"假数据"让网站好看点,一般公司都是从AMAZON的店铺上把热销的产品review放到网站上,无奈AMAZON防爬虫的功夫一流(主要是我懒得再写爬虫有现成的为什 ...

  8. magento 在产品页添加评论 Add Review Form in Magento Product View Page

    Magento产看产品评论需要点击到另外一个页面中,这种设计对于用户体验和SEO都相当不利.一方面用户无法在产品页面查看该产品的一些用户评 价,另外,搜索引擎也会收录很多与产品无关的页面.那么如何让产 ...

  9. magento 根据产品id,获取产品信息

    假设产品的id 存在变量$id中 那么 $_product = Mage::getModel('catalog/product')->load($id); 打印数据信息: var_dump($_ ...

最新文章

  1. HTML在表格右边增加一个表格,如何在表格右侧增加一列
  2. Guava之RateLimiter的设计
  3. 2017 全球超大规模数据中心已超过 390 个,中国仅占 8%
  4. 直播回顾 | 数据驱动实践的三大运营场景讲解
  5. 语言怎么把横的光标变成竖的_想练字,先会学会控笔吧!基础都不牢,怎么练招式?...
  6. python面向对象(2)—— 继承(3)
  7. 如何用Vue实现简易的富文本编辑器,并支持Markdown语法
  8. th标签能包裹select吗_电影《八佰》过后,他能摘掉马思纯前男友标签了吗?
  9. unity3d 随机物体生成器 工具
  10. Leecode刷题热题HOT100(3)——无重复字符最长子串
  11. A Tour of the Dart Language(译文):五控制流语句
  12. 《程序是怎样跑起来的》第七章
  13. Linux下的tar命令
  14. 怎么把cad做的图分享给别人_CAD命令大全分享,作图快人两步
  15. java毕业设计彩妆销售网站Mybatis+系统+数据库+调试部署
  16. 《Thinking in UML》学习1——参与者与用例
  17. 常见十大量化投资策略
  18. 如何linux删除文件夹,linux删除文件夹,教您电脑的linux怎么样删除文件夹
  19. Win-mac版 AE 2018安装附教程
  20. 3dmax材质丢失插件_常见3DMAX插件导出模型丢失贴图问题

热门文章

  1. Almost Arithmetic Progression(CF-978D)
  2. 简单算术表达式求值(信息学奥赛一本通-T1397)
  3. 计算并联电阻的阻值(信息学奥赛一本通-T1015)
  4. 16 WM配置-策略-激活存储类型搜索(Storage Type Search)
  5. php get请求_《细说PHP》第四版 样章 第23章 自定义PHP接口规范 10
  6. VS2019/openGL/freeglut配置
  7. 笨方法“学习python笔记之字符串
  8. Ubuntu 在终端下使用命令行打开pdf文件
  9. torchvision.datasets.ImageFolder使用详解
  10. Bootstrap-CSS-按钮-图片-辅助类-响应式