Magento – Get Product Name and Stars in All Reviews Page

magento-1.9

At the moment i have this piece of code working, with a little help. But last thing is that i would like the product name to show instead of the product id numberand i would like to show the stars given in the review. Thanks for helping.

<?php 
$Collection=Mage::getModel('review/review')->getCollection() 
->setPageSize(5) 
->addStoreFilter(Mage::app()->getStore()->getId()) 
->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED) 
->addRateVotes() 
->setDateOrder(); 

$_items = array_reverse( $Collection->getItems()); 
foreach ($_items as $_review): 
$productId = $_review->getentity_pk_value(); 
$_review->getTitle(); 
$_votes = $_review->getRatingVotes(); 
$_review->getDetail(); 
$this->formatDate($_review->getCreatedAt()); 
$this->__('[Posted %s]', $this->formatDate($_review->getCreatedAt()), 'long'); 
echo "<ul><h3>".$productId = $_review->getentity_pk_value()."</h3>";
echo "<li><h4>".$_review->getTitle()."</h4></li>"; 
echo "<li>".$_review->getDetail()."</li>";
echo "<li>". $this->formatDate($_review->getCreatedAt())."</li>"; 
endforeach; 
?>

Best Answer

I have just had a look at the code for this within:

template/review/product/view/list.phtml

Then added the ratings from here to your code. Replace your code within your phtml file with below:

<?php 
$Collection=Mage::getModel('review/review')->getCollection() 
    ->setPageSize(5) 
    ->addStoreFilter(Mage::app()->getStore()->getId()) 
    ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED) 
    ->addRateVotes() 
    ->setDateOrder('created_at', 'asc'); 
$_items = array_reverse( $Collection->getItems());

foreach ($_items as $_review): 
    $productId = $_review->getentity_pk_value(); 
    $current_product=Mage::getModel('catalog/product')->load($productId);
    echo '<a href="' . $current_product->getProductUrl() . '"><h2>' . $current_product->getName() . '</h2></a>';
    echo $_review->getTitle(); 
    echo $_review->getDetail();
    echo $this->formatDate($_review->getCreatedAt()); 
    $_votes = $_review->getRatingVotes();
    if (count($_votes)): ?>
        <table class="ratings-table">
        <colgroup>
            <col class="review-label" />
            <col class="review-value" />
        </colgroup>
        <tbody>
            <?php foreach ($_votes as $_vote): ?>
            <tr>
                <th><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
                <td>
                    <div class="rating-box">
                        <div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;"></div>
                    </div>
                </td>
            </tr>
            <?php endforeach; ?>
        </tbody>
        </table>
    <?php endif; ?>
<?php endforeach; ?>
Related Topic