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!
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:
Obviously now you can do something like:
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: