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

Problem with custom attribute
 
danilodimoia
Member
 
Total Posts:  36
Joined:  2008-04-21
Chieti
 

Hi, I’ve created an attribute from admin (attribute ‘foo’) and now I would like to display its value in listing product page, but it’s seems it’s not possible.
After I’ve created attribute I’ve add some code on catalog.xml like this:

<action method="addAttribute"><code>foo_attribute</code></action>
in these sections: category_default_layout, category_layered_navigation, product_view but it works only in product-info-box DIV in view.phtml.... insert my custom attribute in related products, upsells products (in view page) and in listing page doesn’t work.

Any hint, please?
Danilo

 
Magento Community Magento Community
Magento Community
Magento Community
 
tman_f
Sr. Member
 
Total Posts:  85
Joined:  2008-02-12
 

@danilodimoia:

From where you are calling your product collection, you need to manually add the addtribute. Instance:

$collection->addAttributeToSelect(’foo’);

Now you should be able to use it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
danilodimoia
Member
 
Total Posts:  36
Joined:  2008-04-21
Chieti
 

Hi, I’m working on list.phtml but it doesn’t work. There’s no $collection var. Maybe I have to modify other file? In which file there is product collection? thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
tman_f
Sr. Member
 
Total Posts:  85
Joined:  2008-02-12
 

Sorry I was so vague. The var $collection was just a representation of any product collection. For that phtml file, you will find it’s corresponding block class in Mage/Catalog/Block/Product/List.php

Around line 60-64 (depending on which production version you are using) you will see an assignment to the instance variable this->_productCollection. The default statement is $layer->getProductCollection;

You need to add the addAttributeToSelect(’foo’) method call to that statement.

So it should look like this:

$this->_productCollection = $layer->getProductCollection()->addAttributeToSelect(’foo’);

or you could add it on the next line like this:

$this->_productCollection->addAttributeToSelect(’foo’);

But the latter can only be used after the call to $layer requesting the collection.

That should do the trick.

 
Magento Community Magento Community
Magento Community
Magento Community
 
danilodimoia
Member
 
Total Posts:  36
Joined:  2008-04-21
Chieti
 

Yes, it does the trick grin
Thanks!

Danilo

P.S. Upgrading magento version, if Mage/Catalog/Block/Product/List.php is rewritten, I have to repeat that step, right?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top