0

I have currently got to the point whereby my site loads all of the reviews for a product and then only shows the first ten on the page. However, as there are tens of thousands of reviews on one particular product, when it tries to load every one of them it kills the page.

The line:

<?php $_items = $this->getReviewsCollection()->getItems();?>

Is where you could suggest the change needs to be made (this being inside Review/product/view/list_tab.phtml). However, using setPageSize(); or limit(); brings up the error of trying to use the method on a non object.

Any approach to this problem would be welcome as this is obviously the most bought product for the store! Thank you in advance

2

1 Answer 1

0

Your review tab in product view page is lack with toolbar. So the solution is adding toolbar block inside your review tab section. From your question, it is not clear that which block that holds CUSTOMER REVIEW section that comes under Review tab.

For the sake of better understanding, I assumes it is a block with name customer.review.in.product.view. In that case, you need to do a layout update somewhat like this

File : app\design\frontend\<package>\<theme>\layout\local.xml

<layout>
    <catalog_product_view>
        <reference name="content">
            <block type="page/html_pager" name="product_review_list.toolbar" />
        </reference>
    </catalog_product_view>
</layout>

This layout update just inserts a toolbar block inside product view page layout. Job is not over. Now we need to set toolbar block with collection. In this case it is review collection.

For this, find your backend class definition for the block customer.review.in.product.view and put this code inside

protected function _prepareLayout()
{
    parent::_prepareLayout();

    if ($toolbar = $this->getLayout()->getBlock('product_review_list.toolbar')) {
        $toolbar->setCollection($this->getReviewsCollection());
        $this->setChild('toolbar', $toolbar);
    }

    return $this;
}

Let us analyse the code here. The method that we used here is _prepareLayout(). This method will invoke during layout preparation. It first try to get a block with name product_review_list.toolbar. Since we define this block through our layout update, it will get the find our custom block successfully.

Next it sets review collection to this block. In order to set the review collection, it is very important that, customer.review.in.product.view block class should extend the class Mage_Review_Block_Product_View.This is because, this class is the place where review collection is loading. I hope the assumed block extends this block. Otherwise this wont work.

Finally our toolbar block is setting as a child block for our review block. You are done. Clear the cache and load the page. It will now paginate review section in your product view page.

I need to mention that, I didn't try this code. That is because, I cannot regenerate the situation with given details. But it should work I guess.

2
  • Thank you for your answer, It is very detailed and has actually helped me on another project to load reviews more efficiently. It, however, couldn't help with this particular case due to it still loading too many reviews for the page. I ended up going to the getReviewsCollection() method inside of the view.php from the review code in the core. After moving it to local and changing the method so that the collection itself i.e. $this->_reviewsCollection was limited to load a smaller amount of review collection objects through using `$this->_reviewsCollection->getSelect()->limit(Whatever); Commented Sep 29, 2014 at 9:39
  • you can try this code. However i am not sure whether it resolves your problem $toolbar->setCollection($this->getReviewsCollection())->setLimit(20); Commented Sep 29, 2014 at 10:29

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.