Skip to content

Instantly share code, notes, and snippets.

@byhbt
Last active September 14, 2018 07:31
Show Gist options
  • Save byhbt/175003048fece776345490331f2ce364 to your computer and use it in GitHub Desktop.
Save byhbt/175003048fece776345490331f2ce364 to your computer and use it in GitHub Desktop.
Magento get current product from a review
<?php
// https://magento.stackexchange.com/questions/178454/get-product-name-and-stars-in-all-reviews-page
$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->getEntityPkValue();
$currentProduct=Mage::getModel('catalog/product')->load($productId);
echo '<a href="' . $currentProduct->getProductUrl() . '"><h2>' . $currentProduct->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; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment