0

I have created a custom module that attaches some information to each product. Now, I want to show the custom information on Catalog page under product name.

Here is snapshot to show you what I am trying to do.

Catalog page

Here is my layout xml

<?xml version="1.0"?>
<!--
/**
 * Custom module

 */
-->
<layout>
    <catalog_category_default translate="label">   
        <reference name="name.after">
            <block type="catalog/product_list" name="custom_content" template="custommodule/default.phtml"/>
        </reference>              
    </catalog_category_default>
</layout>

But this is not working. Is it possible to render custom content under product name without modifying any .phtml files?

Many Thanks!

Tahir Yasin
  • 11,489
  • 5
  • 42
  • 59

2 Answers2

0

I'm aware that this is a quick and dirty hack that more diligent magento devs will sneer at, but it will give you the result you want and is easy for you to impliment

The 'correct' solution probably involves writing a custom block and calling it in the foreach loop of your app/design/frontend/YourPackage/YourTheme/template/product/list.phtml - however, I can offer you a quick and dirty hackaround that shouldn't tax you too much. You can do it very easily by abusing the product attributes system.

First create a new product attribute in the attribute set used by your product. We'll use this to store the custom content we want to inject between your product name and price. For the sake of this example we'll call it customcontent. Make sure you set the attribute's Visible on "Product View Page on Front-end" value to 'No'.

Edit your product and set this new attribute equal to your desired custom content - it's fine you use html tags in here too. By default, product attributes have (for some reason) an arbitrary limit of 30 characters but if you need it to hold a longer string you can easily change this by editing app/code/mage/eav/model/entity/Attribute.php and changing the value of ATTRIBUTE_CODE_MAX_LENGTH.

Then in your app/design/frontend/YourPackage/YourTheme/template/product/list.phtml and find the following line of code somewhere around line 49

<?php foreach ($_productCollection as $_product): ?>

directly after it insert the following:

<?php  $_customcontent =$_product->getResource()->getAttribute('customcontent')->getFrontend()->getValue($_product);?>

You've now stored the string from your products customcontent attribute in a variable called $_customcontent

So if you find the following line in your list.phtml

<h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a></h2>

you can easily add a new paragraph or heading beneath it and populate it with your custom content using

<?php echo $_customcontent ?>

I know this probably represents a deeply unorthodox solution, but it does work and can be acheived very quickly, and without requiring you to know anything about writing your own custom blocks.

Ben Edwards
  • 168
  • 13
  • Thanks for our answer but I clearly mentioned in my question that I don't want to modify theme's list.phtml file, I want to implement this with the help my module's layout xml and custom .phtml file. – Tahir Yasin Nov 11 '15 at 05:34
0

Can you try :

<catalog_categoryd_default>
 <reference name="content">
  <block type="catalog/product_list" name="custom_content" template="custommodule/default.phtml" after="nameofTheNameBlock"/>
</reference>
</catalog_categoryd_default>
wmk
  • 4,598
  • 1
  • 20
  • 37
Mihir Bhende
  • 8,677
  • 1
  • 30
  • 37