Created
August 9, 2016 07:27
-
-
Save tobiasdalhof/d3520cad434aa3eb10b68e71c1667039 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Hint: I stored the rating_header.phtml under /template/rating. | |
* Load the template whereever you want by doing <?php echo $this->getLayout()->createBlock('core/template')->setTemplate('rating/rating_header.phtml')->toHtml(); ?> in your template file. | |
*/ | |
/** | |
* Getting reviews collection object. | |
*/ | |
$reviews = Mage::getModel('review/review') | |
->getResourceCollection() | |
->addStoreFilter(Mage::app()->getStore()->getId()) | |
->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED) | |
->setDateOrder() | |
->addRateVotes(); | |
/** | |
* Getting average of ratings/reviews. | |
*/ | |
$avg = 0; | |
$totalrv = 0; | |
$totalrvper =0; | |
/** | |
* Check if the current page is a product page. | |
*/ | |
$isProductPage = false; | |
if ( Mage::registry('current_product') ) | |
{ | |
$isProductPage = true; | |
} | |
if (count($reviews) > 0) | |
{ | |
foreach ($reviews->getItems() as $review) | |
{ | |
foreach( $review->getRatingVotes() as $vote ) | |
{ | |
$totalrv = $totalrv+$vote->getValue(); | |
$totalrvper = $totalrvper + $vote->getPercent(); | |
} | |
} | |
// Total reviews. | |
$totalrv = $totalrv / count($reviews->getItems()); | |
// Total reviews in percent. | |
$totalrvper = ($totalrvper)/ count($reviews->getItems() ); | |
// Total reviews rounded. | |
$avgrate = round($totalrv, 1); | |
} | |
?> | |
<div class="header-rating"> | |
<div class="ratings"> | |
<div class="rating-box"> | |
<div class="rating" style="width:<?php echo $totalrvper; ?>%"></div> | |
</div> | |
</div> | |
<?php if ( $isProductPage ): ?> | |
<div class="rating-text"> | |
<span>Unsere Kunden bewerten uns mit <?= $avgrate ?> von 5 Sternen, basierend auf <a title="Alle Produktbewertungen durch unsere Kunden" href="/produktbewertungen-durch-unsere-kunden"><?= count($reviews->getItems()) ?> Produktbewertungen</a>.</span> | |
</div> | |
<?php else: ?> | |
<div class="rating-text" itemprop="aggregateRating" itemscope="" itemtype="http://schema.org/AggregateRating"> | |
<meta itemprop="itemReviewed" content="Your Company"> | |
<meta itemprop="ratingValue" content="<?= $avgrate ?>"> | |
<meta itemprop="reviewCount" content="<?= count($reviews->getItems()) ?>"> | |
<span>Unsere Kunden bewerten uns mit <?= $avgrate ?> von 5 Sternen, basierend auf <a title="Alle Produktbewertungen durch unsere Kunden" href="/produktbewertungen"><?= count($reviews->getItems()) ?> Produktbewertungen</a>.</span> | |
</div> | |
<?php endif; ?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment