2

I created a custom block class for the bestseller products:

<?php

class Company_Bestseller_Block_Bestseller extends Mage_Catalog_Block_Product_Abstract
{
    public function getBestsellerProducts()
    {
        $storeId = (int) Mage::app()->getStore()->getId();

        $date = new Zend_Date();
        $toDate = $date->setDay(1)->getDate()->get('Y-MM-dd');
        $fromDate = $date->subMonth(1)->getDate()->get('Y-MM-dd');

        $collection = Mage::getResourceModel('catalog/product_collection')
            ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
            ->addStoreFilter()
            ->addPriceData()
            ->addTaxPercents()
            ->addUrlRewrite()
            ->setPageSize(5);

        $collection->getSelect()
            ->joinLeft(
                array('aggregation' => $collection->getResource()->getTable('sales/bestsellers_aggregated_monthly')),
                "e.entity_id = aggregation.product_id AND aggregation.store_id={$storeId} AND aggregation.period BETWEEN '{$fromDate}' AND '{$toDate}'",
                array('SUM(aggregation.qty_ordered) AS sold_quantity')
            )
            ->group('e.entity_id')
            ->order(array('sold_quantity DESC', 'e.created_at'));

        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

        return $collection;
    }
}

Now I try to get the rating summary with the following code in my PHTML block:

<?php foreach ($this->getBestsellerProducts() as $_product): ?>
    <?php if($_product->getRatingSummary()): ?>
        <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
    <?php endif; ?>
<?php endif; ?>

Unfortunately the summary stays empty. How I can get this information?

6

Add this line before return $collection

Mage::getModel('review/review')->appendSummary($collection);
  • I am getting same issue in magento 2. Can anyone have solution for this? – Shiwani May 6 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.