dongshan9619 2011-06-06 09:29
浏览 14
已采纳

Magento - 在评论模块之外显示随机评论

I am using Magento 1.5 and am attempting to include a small box in my sidebar for a random product showing a product image, product name, star rating and part of a review.

I have managed to get Magento displaying a random product in the sidebar, unfortunately I cannot seem to find a way to select the random product based on if it has a review or not, and I also cannot find a way to load a review summary into the sidebar template I'm using.

I found the following piece of example code but it just throws the good old call to non object error.

<?php

$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
)
*/

?>

if anyone has any ideas how to get this working, it would be greatly appreciated.

Thanks in advance!

  • 写回答

3条回答 默认 最新

  • duanduo0520 2011-06-06 09:36
    关注

    The reason you are getting that error is because of the quotes you are using. Use ' instead.

    In response to your edit, this is how you would go ahead and load 5 random products that have a review:

    $review = Mage::getModel('review/review');
    $collection = $review->getProductCollection();
    $collection
            ->addAttributeToSelect('*')
            ->getSelect()
                    ->limit(5)
                    ->order('rand()');
    $review->appendSummary($collection);
    
    foreach($collection as $product) {
            var_dump($product->debug());
    }
    

    Obviously now you can do something like:

    $product->getRatingSummary()
    

    to extract rating data, etc.

    Of course it is up to you to create a block to put this in (or the bad way -> just put it in some template).

    Have fun ;)

    Third edit in response to your question:

    /* Getting summary title / body. */
    $title = $product->getTitle();
    $body  = $product->getDetail();
    
    /* To get (what I assume is) 'star' rating. */
    $ratingSummary = $product->getRatingSummary();
    $starRating = $ratingSummary['rating_summary'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP