friends. How to add product images on the My Product Reviews page like this mockup design
Magento – Adding Product Image in My Product Reviews page
product-imagesreview
Related Solutions
There are several routes in the Mage_Reviews
module, and you likely don't want to disable them all. Here's a list gleaned from Mage/Reviews/controllers/:
review/customer/(index)
- customer account view of their reviewsreview/customer/view/id/{review id}
- customer account view of a single reviewreview/product/list/id/{product id}/[(category)/{category id}]
- list of reviews for a productreview/product/post
- process action for posting a reviewreview/product/view/id/{review id}
- individual view for a single product review - keep?
Bold = paths which you do/might want to map & redirect, italics = paths to keep.
Whereas there is content which can and should be used for the review requests, this seems best accomplished using an observer. To catch the review/product/list
route the observer should observe the controller_action_predispatch_review_product_list
event in the frontend event area and set an HTTP 301 redirect to the product page. The 301 will of course be used by search engines to update links and transfer some of the link juice.
<frontend>
<events>
<controller_action_predispatch_review_product_list>
<observers>
<your_module>
<class>your_module/observer</class>
<method>redirectReviewListToProductView</method>
</your_module>
</observers>
</controller_action_predispatch_review_product_list>
</events>
</frontend>
And in your module's observer, the redirect method:
/**
* Redirect requests for review page to product page,
* which now contains review contents. Relies on the
* accommodation of request object redirect in the
* elseif condition which is present in
* Mage_Review_ProductController::listAction().
*
* Observes
* controller_action_predispatch_review_product_list
*
* @see Mage_Review_ProductController::listAction()
* @see Mage_Core_Controller_Varien_Action::preDispatch()
*
* @param Varien_Event_Observer $observer
*/
public function redirectReviewListToProductView(Varien_Event_Observer $observer)
{
$request = $observer->getControllerAction()->getRequest();
/* @var $request Mage_Core_Controller_Request_Http */
//log to custom logfile
//Mage::log($request->getServer('HTTP_REFERER').': '.$request->getPathInfo(), Zend_Log::INFO, 'review_redirects.log',true);
//$toUrl will be empty if missing id param or invalid product ID.
$toUrl = Mage::getModel('catalog/product')->load($request->getParam('id'))->getProductUrl();
//$request->_forward() is protected (no idea why), so implement noroute (404) manually.
if (!$toUrl) {
$request->initForward();
$request->setActionName('noroute')->setDispatched(false);
}
else {
//review/product/list accommodates redirects, so this should work
$observer->getControllerAction()->getResponse()->setRedirect($toUrl);
$request->setParam('id',false);
}
}
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 ;)
Best Answer
The product collection with the reviews is built in
Mage_Review_Block_Customer_List::_construct()
but the collection contains only the name attribute of the product.So you need to rewrite that method and add the image attribute.
So create your module and add this in the config.xml
then create the file
[Namespace]/[Module]/Block/Customer/List.php
with this contentThen in the template
app/design/frontend/{package}/{theme}/template/review/customer/list.phtml
add this to get the image where ever you need it like this:Feel free to change the size of the image to what ever you need.