The below should get you onto the right track. (expanded to explain in more detail, as per comments)
The default behavior for reviews is to do a form post onto the review controller. This form post gets the product id for the product that is to be reviewed.
you can see this variable fetched in the block code Mage_Review_Block_Form::getAction() - $productId = Mage::app()->getRequest()->getParam('id', false);
This is then used to get the product data (for the name), and to build the review form post url.
Since you want to display the form on the category page (per product), you cannot do this, and need another way to set the correct product(id). This is easy, by just passing in the product data, for the current product, via the .phtml using a line like this:
<?php echo $this->getChild('review_form')->setProduct($_product)->toHtml(); ?>
It is best to just pass the entire product object, since you can then use any of the product data in the review block.
To make it all work, you need to create a new block which extends the core review block class Mage_Review_Block_Form
(not rewrite, just extend), and adjust functionality to pull the product id from the passed product object.
you want to extend any functions that get the productId to use your given productid (see later in phtml)
This is needed to allow each form to be posting for each product, else they will all post for one product.
as an example the method Mage_Review_Block_Form::getAction()
looks like this:
public function getAction()
{
$productId = Mage::app()->getRequest()->getParam('id', false);
return Mage::getUrl('review/product/post', array('id' => $productId));
}
and you will need to change that to pull the productId from $this->getProduct()->getId();
(again, see later in phtml adjustment how that is set)
Next you need to adjust the layouts to include the review form.
thus in catalog.xml you need to get the review form layout into the catalog_category layout
You must set the block to your new block, and not the core review block, thus allowing the .phtml to call your methods, which change the behavior to get the product data from the different place.
place this xml block:
<block type="YOUR_MODULE_NAMESPACE/YOUR_BLOCK" name="product.review.form" as="review_form">
<block type="page/html_wrapper" name="product.review.form.fields.before" as="form_fields_before" translate="label">
<label>Review Form Fields Before</label>
<action method="setMayBeInvisible"><value>1</value></action>
<action method="setElementClass"><value>rewards</value></action>
</block>
</block>
into the <catalog_category_default translate="label">
layout area, contained within <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
(you may also need to place it in the anchor category layout area)
This then sets the review form to be a child block of catalog/product_list
now, to make it display, you need to edit the list.phtml file (.../template/catalog/product/list.phtml) to include the review form and then pass it the current product
This is done simply by using
<?php echo $this->getChild('review_form')->setProduct($_product)->toHtml(); ?>
For completeness, the full layout xml section:
<catalog_category_default translate="label">
<label>Catalog Category (Non-Anchor)</label>
<reference name="left">
<block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
</reference>
<reference name="content">
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
<!-- The following code shows how to set your own pager increments -->
<!--
<action method="setDefaultListPerPage"><limit>4</limit></action>
<action method="setDefaultGridPerPage"><limit>9</limit></action>
<action method="addPagerLimit"><mode>list</mode><limit>2</limit></action>
<action method="addPagerLimit"><mode>list</mode><limit>4</limit></action>
<action method="addPagerLimit"><mode>list</mode><limit>6</limit></action>
<action method="addPagerLimit"><mode>list</mode><limit>8</limit></action>
<action method="addPagerLimit" translate="label"><mode>list</mode><limit>all</limit><label>All</label></action>
-->
</block>
<action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
<action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
<action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
<action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
<action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
<block type="YOUR_MODULE_NAMESPACE/YOUR_BLOCK" name="product.review.form" as="review_form">
<block type="page/html_wrapper" name="product.review.form.fields.before" as="form_fields_before" translate="label">
<label>Review Form Fields Before</label>
<action method="setMayBeInvisible"><value>1</value></action>
<action method="setElementClass"><value>rewards</value></action>
</block>
</block>
</block>
</block>
</reference>
</catalog_category_default>
the above in action, ugly, as the design does not allow for a form, but I am sure your's will ;)
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.
Best Answer
you use below script to get all reveiew and rating .