Malcolm Knott
Malcolm Knott

Reputation: 111

Adding product reviews to the category page

I need to add product reviews to the list view of the category page, not just the summary rating. Need to add the “Detailed star rating”, “Summary of review”, “Nickname” and “Body of review”. Much the same as you would see it on the product review page.

I’ve had a look at the base Magento template file for the product review page app/design/frontend/base/default/review/product/view/list.phtml. There is an array $_items = $this->getReviewsCollection()->getItems(); that contains all the review info that I need.

However if I try to use $_items = $this->getReviewsCollection()->getItems(); in the category template file app/design/frontend/default/my_theme/template/catalog/product/list.phtml I get the following error

“Fatal error: Call to a member function getItems() on a non-object”.

How do I get past this error, or am I going about this the wrong way? Any advice or tips would be appreciated.

Upvotes: 1

Views: 1412

Answers (1)

Vishal
Vishal

Reputation: 900

Hello you will use below code may be help you.

$entity_ids = array(22, 23);

$reviewcollection = Mage::getModel('review/review')->getCollection()
    ->addStoreFilter(Mage::app()->getStore()->getId())
    ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
    ->addFieldToFilter('entity_id', Mage_Review_Model_Review::ENTITY_PRODUCT)
    ->addFieldToFilter('entity_pk_value', array('in' => $entity_ids))
    ->setDateOrder()
    ->addRateVotes();


$_items = $reviewcollection->getItems();

Upvotes: 2

Related Questions