2

friends. How to add product images on the My Product Reviews page like this mockup design

My Product Reviews page with product images

5

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

<blocks>
     <review>
         <rewrite>
             <customer_list>[Namespace]_[Module]_Block_Customer_List</customer_list>
         </rewrite>
     </review>
</blocks>

then create the file [Namespace]/[Module]/Block/Customer/List.php with this content

<?php 
class [Namespace]_[Module]_Block_Customer_List extends Mage_Review_Block_Customer_List
{
    protected function _construct()
    {
        parent::_construct();
        $this->collection->addAttributeToSelect('image');
    }
}

Then 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:

<img src="<?php echo $this->helper('catalog/image')->init($_review, 'image')->resize(200,150)?>" alt="<?php echo $this->escapeHtml($_review->getName())?>" />

Feel free to change the size of the image to what ever you need.

  • Hi Marius (@marius), thanks for help and very fast answer. I have try it but the result is No Image Available [i.imgur.com/2ddw6aw.png]. I have try with extend it to code\local\Mage\Review, but it did not work. Then I make module code\local\KS\Myreview, but it did not work too. The following is my code link : [pastebin.com/jr4rGm9m] (sorry, should I put it as a link in the comments or put my question / edit questions based on your guidelines?). I have clear cache and make sure image of product in admin set to Base Image for each store view. – Andhi Irawan Jul 1 '15 at 1:48
  • and somehow I did not know it sometimes makes my apache crashes – Andhi Irawan Jul 1 '15 at 4:32
1

I did not create a new module and not also make extend. I tried the following in app\design\frontend\andi\default\template\review\customer\list.phtml and successfully.

<?php foreach ($this->getCollection() as $_review): $_product = Mage::getModel('catalog/product')->load($_review->getEntityPkValue());?>

<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(160,227); ?>" width="160" height="227" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'image'), null, true) ?>" />

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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