题
我有一个可配置的产品,我试图从中获得评论
$ mythemename/catalog/product/view.phtml
/**
* Product view template
*
* @see Mage_Catalog_Block_Product_View
* @see Mage_Review_Block_Product_View
*/
$_product = $this->getProduct();
我需要5星,4星,3星,2星和1星的小组计数。像这样
我已经完成了以下操作 关联 (检查 @Sinclairfr的帖子),这给了我与产品相关的完整评级。
<?php $zoo = new Mage_Rating_Block_Entity_Detailed(); ?>
<?php echo $zoo->toHtml(); ?>
还有这个
$review = Mage::getModel('review/review');
$collection = $review->getProductCollection();
$collection
->addAttributeToSelect('*')
->getSelect()
->limit(5)
->addFieldToFilter('product_id', $_product->getId());
$review->appendSummary($collection);
zend_debug::dump($review);
通过这个 关联
仍然没有用
解决方案
您可以通过以下代码获得所有的投票。请注意,SetenTityPkFilter正在设置产品ID。
$votesCollection = Mage::getModel('rating/rating_option_vote')
->getResourceCollection()
->setEntityPkFilter($productId)
->setStoreFilter(Mage::app()->getStore()->getId())
->load();
这将为您提供每种类型的投票。因此,在默认商店中,您将在此收藏中获得三个项目。评级是根据价格,质量和价值完成的。
然后,您可以循环浏览集合中的每个项目,并将它们添加到星级评级中。投票项目的示例数据是:
array(10) {
["vote_id"]=>
string(3) "283"
["option_id"]=>
string(1) "9"
["remote_ip"]=>
string(9) "127.0.0.1"
["remote_ip_long"]=>
string(10) "2130706433"
["customer_id"]=>
NULL
["entity_pk_value"]=>
string(2) "27"
["rating_id"]=>
string(1) "2"
["review_id"]=>
string(2) "95"
["percent"]=>
string(2) "80"
["value"]=>
string(1) "4"
}