当前位置: 动力学知识库 > 问答 > 编程问答 >

php - How do I add product ratings to a collection?

问题描述:

I have the following code to allow me to show products with a "featured" attribute, on the front page of my store.

$_productCollection=Mage::getResourceModel('catalog/product_collection')

->addAttributeToSelect('*')

->addAttributeToFilter('is_featured', 1)

->addAttributeToFilter('status', 1)

->joinField('value','catalog_product_entity_tier_price','value', 'entity_id=entity_id','{{table}}.website_id='.$storeId, 'left')

->setPageSize(9)

->setStoreId($storeId)

->addStoreFilter($storeId);

The issue is, I need to be able to show the product ratings ($this->getReviewsSummaryHtml($_product, 'short') in my normal category listing)

How can I add the data into the collection to allow me to use:

if($_product->getRatingSummary()):

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

endif;

网友答案:

You can use the following in your collection loop:

Mage::helper('review/product')->getReviewsSummaryHtml($_product, false, true);

Your loop should look something like:

foreach($_productCollection as $_product)
{
    echo Mage::helper('review/product')->getReviewsSummaryHtml($_product, false, true);
}
网友答案:

This worked for me, in product collection

$reviewHelper = $this->getLayout()->createBlock('review/helper');
echo $reviewHelper->getSummaryHtml($_product, 'short', false);

Reference Here

分享给朋友:
您可能感兴趣的文章:
随机阅读: