Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 4
Displaying Attributes in Catalogue List
 
Sean Yeomans
Jr. Member
 
Avatar
Total Posts:  29
Joined:  2008-04-02
Winnipeg
 

How can I display product attributes in the catalog list view, I’m using

<?php if($_additional $this->getAdditionalData()): ?>
                    
                        <?php 
foreach ($_additional as $_data): ?>
                            <?php 
echo $_data['label'] ?>
                            <?php 
echo $_data['value'] ?>
                        <?php 
endforeach; ?>
                        
                    <?php 
endif; ?>
but that doesn’t seem to do anything… is this function
$this->getAdditionalData()
not available to the catalog page?  Where can I find what functions ARE available to any given page?

for further info, here is the full code block from template/catalog/product/list.phtml

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

    
<div class="listing-item <?php if( ++$_iterator == sizeof($_productCollection) ): ?>last<?php endif; ?>">
        
<?php // Product Image ?>
        
        
<div class="product-image">
            <
h5><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName())?></a></h5>
            <
a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                <
img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135, 135); ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>"/>
            </
a>
        </
div>

        
<?php // Product description ?>
        
<div class="product-shop">
            
            <
div class="description">
                <
a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><small><?php echo $this->__('?'?></small></a>
                
<?php echo $_product->getShortDescription() ?>
            
</div>
            <
div class='detail_box style'>
                <
h4>style</h4>
            </
div>
            <
div class='detail_box absorbency'>
                <
h4>absorbency</h4>
                 
<?php if($_additional $this->getAdditionalData()): ?>
                    
                        <?php 
foreach ($_additional as $_data): ?>
                            <?php 
echo $_data['label'] ?>
                            <?php 
echo $_data['value'] ?>
                        <?php 
endforeach; ?>
                        
                    <?php 
endif; ?>
            
</div>
            
<?php if($_product->getRatingSummary()): ?>
                
<div class='detail_box rating'>
                    <
h4>rating</h4>
                    
<?php echo $this->helper('review/product')->getSummaryHtml($_product?>
                
</div>
            
<?php endif; ?>
            
<div class='detail_box quantity'>
                <
h4>Qty</h4>
                    
<?php echo $this->helper('catalog/product')->getPriceHtml($_producttrue?></div>
            <
div class='detail_box price'>
                <
h4>price</h4>
                
<?php echo $this->helper('catalog/product')->getPriceHtml($_producttrue?></div>
            <
div class='detail_box action'>
                <
h4>action</h4>
                 
<?php if($_product->isSaleable()): ?>
                    
<button class="form-button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart'?></span></button>
                
<?php else: ?>
                    
<div class="out-of-stock"><?php echo $this->__('Out of stock'?></div>
                
<?php endif; ?>
            
</div>
            
            <
div class="clear"></div>
        
        </
div>
    </
div>
<?php endforeach; ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
kylewhat
Member
 
Total Posts:  45
Joined:  2008-06-02
 

I’m trying to figure out the same thing.  The only thing that I’ve managed to show up on the list is the sku by putting

<?=$_product->getsku()?>

in app/design/frontend/default/default/template/catalog/product/list.phtml

sku is the name of the preinstalled attribute “sku” and one would think that <?=$_product->getATTRIBUTENAME() ?> would work… but it doesn’t.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikkstocks
Member
 
Total Posts:  47
Joined:  2008-06-08
 

http://www.magentocommerce.com/wiki/how-to/add-attributes-to-product-grid apparently, but i cant get it to work…

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikkstocks
Member
 
Total Posts:  47
Joined:  2008-06-08
 

scratch that, got it to work. the “getMyAttribute()” they refer to in the link i just posted should actually be “getmy_attribute()”

 
Magento Community Magento Community
Magento Community
Magento Community
 
repeaterstore
Member
 
Total Posts:  35
Joined:  2007-11-16
 

I’m not sure about Nikkstocks last post...I thought the “myattribute” part of “getmyattribute” depends on what your attribute is called. So if the attribute I want to display is “catalogdescription”, I should use “getcatalogdescription”?

I’m having some problems getting this work - can you share what you did to get it running?

 
Magento Community Magento Community
Magento Community
Magento Community
 
repeaterstore
Member
 
Total Posts:  35
Joined:  2007-11-16
 

Looking through the wiki file’s revision history, it looks like they’ve updated that document since you posted, and fixed the problem you were talking about.

I still don’t seem to be able to get this to work though. Can anyone confirm that using getCatalogDescription should work fine, given that my attribute is called CatalogDescription?

 
Magento Community Magento Community
Magento Community
Magento Community
 
repeaterstore
Member
 
Total Posts:  35
Joined:  2007-11-16
 

Ok, got it working smile. I was adding it to the list view instead of the grid view...doh!

 
Magento Community Magento Community
Magento Community
Magento Community
 
sixora
Jr. Member
 
Total Posts:  5
Joined:  2008-08-22
 

Can you please do a little step-by-step presentation with exact locations where you put the code snippets? Thanks a lot.

I can’t get it to work.

 
Magento Community Magento Community
Magento Community
Magento Community
 
skeptic35
Jr. Member
 
Total Posts:  10
Joined:  2008-11-25
 

As the wiki page is slightly confusing I’d like to clear things up a bit. There are actually two things you have to do:
1. Update your xml
2. Update your template
Lets look at an example for an attribute called “Manufacturer”.

In catalog.xml I changed this

<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">
to that (added the action tag)
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
        <
action method="addAttribute"><attribute>Manufacturer</attribute></action>
        <
block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
basically what you do here is make your Attribute known in the product list.

In template/catalog/product/list.phtml you can then display the attribute value like this (be sure to add the output to the correct list layout, ie. ‘list’ or ‘grid’):

<?php echo $_product->getAttributeText('Manufacturer'?>
That is in case your Attribute is one with selectable values. If it was a plain text attribute you’d use
<?php echo $_product->getManufacturer() ?>

Hope that helps.

 
Magento Community Magento Community
Magento Community
Magento Community
 
maarlin
Jr. Member
 
Total Posts:  8
Joined:  2008-07-02
 

Firstly I added new method to class Mage_Catalog_Block_Product_View_Attributes:

function setProduct($productId)
    
{
        
if (!Mage::registry('product') && $productId{
            $this
->_product Mage::getModel('catalog/product')->load($productId);
        
}
    }

Then I’ve added to /app/design/frontend/*/*/template/catalog/product/list.phtml this:

<table class="info">
 
<?php
 $add 
= new Mage_Catalog_Block_Product_View_Attributes();
 
$add->setProduct($_product->getId());
 
$_additional $add->getAdditionalData();
 
?>
 <?php 
foreach ($_additional as $_data): ?>
        
<tr>
            <
th><?php echo $_data['label'] ?></th>
            <
td><?php echo $_data['value'] ?></td>
        </
tr>
 
<?php endforeach; ?>
 
</table>

I hope it will help you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MacKniven
Member
 
Total Posts:  51
Joined:  2009-01-09
 

As asn extension to this, how would I display a custom attribute in a different format?

i.e
I have a custom attribute called publish_date which is a date field.

I want to show this in the category list, so I edited…
/app/design/frontend/default/default/template/catalog/product/list.phtml

and added. <?php echo $_product->getpublish_date()?>

This displays the attribute but shows it as for example 2008-1-12 00:00:00

In the product page itself under Additional Information, this is re-written to display as Jan 12, 2008 when in the product view page. Any suggestions how I can achieve this much nicer format?

Thanks
Gary

 
Magento Community Magento Community
Magento Community
Magento Community
 
Wong8egg
Jr. Member
 
Total Posts:  21
Joined:  2009-03-17
 
skeptic35 - 02 February 2009 12:33 AM

As the wiki page is slightly confusing I’d like to clear things up a bit. There are actually two things you have to do:
1. Update your xml
2. Update your template
Lets look at an example for an attribute called “Manufacturer”.

In catalog.xml I changed this

<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">
to that (added the action tag)
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
        <
action method="addAttribute"><attribute>Manufacturer</attribute></action>
        <
block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
basically what you do here is make your Attribute known in the product list.

In template/catalog/product/list.phtml you can then display the attribute value like this (be sure to add the output to the correct list layout, ie. ‘list’ or ‘grid’):
<?php echo $_product->getAttributeText('Manufacturer'?>
That is in case your Attribute is one with selectable values. If it was a plain text attribute you’d use
<?php echo $_product->getManufacturer() ?>

Hope that helps.

Hi,

I have followed your guide exactly like this:

In list.phtml

<?php $_collectionSize $_productCollection->count() ?>
    <?php $i
=0; foreach ($_productCollection as $_product): ?>
        <?php $i
++ ?>
                            [
                                <?php 
echo $_product->getAttributeText('Brand')?>
                                <?php 
echo $_product->getBrand()?>
                                <?php 
echo $_product->getAttributeText('Manufacturer'?> 
                                <?php 
echo $_product->getManufacturer() ?> 
                            ]
    <?php 
endforeach ?>

and in catalog.xml

<catalog_category_default>
        <
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">
                    <
action method="addAttribute"><attribute>Brand</attribute></action>  
                    <
action method="addAttribute"><attribute>Manufacturer</attribute></action>
                </
block>
            </
block>
        </
reference>
    </
catalog_category_default>

I have also updated “Visible on Catalog Pages on Front-end” in the admin panel.
But it is not working somehow, none of the 4 echo is printing anything. What have I possibility done wrong? Any help is much appreciated.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
skeptic35
Jr. Member
 
Total Posts:  10
Joined:  2008-11-25
 

Dunno. Maybe you added your echos to the wrong part of list.phtml. There are different parts for the different layout types (list or grid).

 
Magento Community Magento Community
Magento Community
Magento Community
 
yban38
Member
 
Avatar
Total Posts:  54
Joined:  2009-02-06
Grenoble, France
 

Hello,

i have the same problem

i do exactly the http://www.magentocommerce.com/wiki/how-to/add-attributes-to-product-grid but doesn’t work for me.

i view a lot of post on the forum but i don’t find the good one.

Please help me

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

Hi all,

I was just trying to see if we could display a custom attribute in the product detail view: not just the value, but th label and type as well. For instance, I we have a dropdown select attribute, can we display that dropdown for the customer to select in place of a custom product option?

If so, what about a text field and text area? Thanks for the replies at your earliest convenience! Normally with attributes their value (defined in the product) is what gets displayed. But we would like to use this in place of a custom product option. Possible?

It all looks right, so I’ll try this out soon.

Thanks foe the dialogue!

maarlin - 11 February 2009 10:02 AM

Firstly I added new method to class Mage_Catalog_Block_Product_View_Attributes:

function setProduct($productId)
    
{
        
if (!Mage::registry('product') && $productId{
            $this
->_product Mage::getModel('catalog/product')->load($productId);
        
}
    }

Then I’ve added to /app/design/frontend/*/*/template/catalog/product/list.phtml this:
<table class="info">
 
<?php
 $add 
= new Mage_Catalog_Block_Product_View_Attributes();
 
$add->setProduct($_product->getId());
 
$_additional $add->getAdditionalData();
 
?>
 <?php 
foreach ($_additional as $_data): ?>
        
<tr>
            <
th><?php echo $_data['label'] ?></th>
            <
td><?php echo $_data['value'] ?></td>
        </
tr>
 
<?php endforeach; ?>
 
</table>

I hope it will help you.
 
Magento Community Magento Community
Magento Community
Magento Community
 
Brent W Peterson
Moderator
 
Avatar
Total Posts:  3217
Joined:  2009-02-26
Minneapolis MN
 

I thought the point of the module ext was not to modify any of the core code?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 4