0

In the review list I've altered the sort based on a custom table.

in app/design/frontend/rwd/theme/template/review/product/view/list.phtml

I've altered

$_items = $this->getReviewsCollection()->getItems();

Into

/** @var Mage_Review_Model_Resource_Review_Collection $collection */
$collection = $this->getReviewsCollection();
$collection->clear();
$collection->getSelect()->joinLeft( array('featured'=>'review_featured'), 'main_table.review_id = featured.review_id', array('featured.featured_number'));
$collection->getSelect()->reset(Zend_Db_Select::ORDER);
$collection->getSelect()->order('featured.featured_number DESC');
$_items = $collection->getItems();

But now the rationg collection is null

/* @var Mage_Rating_Model_Resource_Rating_Option_Vote_Collection $_votes */
$_votes = $_review->getRatingVotes();

How Do I alter the query and keep my collection?

2
  • 2
    Don't do this in the template. Rewrite the block and reimplement getReviewCollection().
    – user4351
    Commented Feb 17, 2015 at 8:49
  • Hi @Melvyn that worked
    – janw
    Commented Feb 17, 2015 at 11:04

1 Answer 1

1

Like @Melvyn suggested in the comments, implementing it in the Block class worked. Not totally sure why and how, but it works.

<?php

class Namespac_Module_Block_Product_View_List extends Mage_Review_Block_Product_View_List {

    public function getReviewsCollection()
    {
        if (null === $this->_reviewsCollection) {
            $this->_reviewsCollection = Mage::getModel('review/review')->getCollection()
                ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
                ->addStoreFilter(Mage::app()->getStore()->getId())
                ->addEntityFilter('product', $this->getProduct()->getId());

            $this->_reviewsCollection->clear();
            $this->_reviewsCollection->getSelect()->joinLeft( array('featured'=>'review_featured'), 'main_table.review_id = featured.review_id', array('featured.featured_number'));
            $this->_reviewsCollection->getSelect()->reset(Zend_Db_Select::ORDER);
            $this->_reviewsCollection->getSelect()->order('featured.featured_number DESC');

        }
        return $this->_reviewsCollection;
    }

}

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.