I'm trying to display the latest 10 review on the homepage. For some reason, they are not sorting by date.

$review = Mage::getModel('review/review');
$collection = $review->getProductCollection();
$collection->addAttributeToSort('created_at', 'DESC');

If I print the SQL generated by $collection->getSelect(), I get the following:

SELECT `e`.`entity_id`, `e`.`type_id`, `e`.`attribute_set_id`,`e`.`name`, 
    `e`.`sku`, `rt`.`review_id`, `rt`.`created_at` AS `review_created_at`, 
    `rt`.`entity_pk_value`, `rt`.`status_id`,`rdt`.`title`, `rdt`.`nickname`, 
    `rdt`.`detail`, `rdt`.`customer_id`,`rdt`.`store_id` 
FROM `catalog_product_flat_1` AS `e` 
    INNER JOIN `review` AS `rt` 
        ON rt.entity_pk_value = e.entity_id 
    INNER JOIN `review_detail` AS `rdt` 
        ON rdt.review_id = rt.review_id 
WHERE (e.status = 1) 
ORDER BY `e`.`created_at` DESC

Ended up changing the select to:

$reviews = Mage::getModel('review/review')->getResourceCollection(); $reviews->addStoreFilter( Mage::app()->getStore()->getId() ) ->addStatusFilter( Mage_Review_Model_Review::STATUS_APPROVED ) ->setDateOrder() ->addRateVotes() ->load();

And the order is now fine....but somehow I lost the review summary. Star ratings I mean.

1 Answer 1


The problem is ORDER BY e.created_at DESC. You're sorting by the created_at of the product table. Try removing your sort line, and replace it with $collection->getSelect()->order('rt.created_at', 'desc'). rt is the review table from looking at your query.

  • Same thing. No luck. Ended up changing how I selected reviews which worked. Updated question.
    – lbn
    Apr 13, 2016 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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