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

How do I echo a specific attribute on the frontend? 
 
nrhammond
Jr. Member
 
Total Posts:  10
Joined:  2008-08-11
 

I have created a new attribute called ‘video’ and it belongs to my default attribute set.  I have a product that is assigned that default attribute set.

My question is how can I get the value of that attribute?  Is there a general function like getAttribute(’video’) that I can use?  For the default attributes they have getName() and getShortDescription().  Is there documentation on this anywhere?

 
Magento Community Magento Community
Magento Community
Magento Community
 
anthonyfojas
Member
 
Total Posts:  33
Joined:  2008-08-19
 

Its different depending on where you want to add it.

This page will show you how to add it to the product listing page, http://www.magentocommerce.com/wiki/how-to/add-attributes-to-product-grid.

On the product view page, the Mage_Catalog_Block_Product_View has a getProduct function (which is called at the top of the catalog/product/view.phtml page.  The product returned should have getters for your custom attributes, so if you have an attribute called “color” $_product->getColor() should return your color.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nrhammond
Jr. Member
 
Total Posts:  10
Joined:  2008-08-11
 

I got that working on the product view page but not on the product list page. 

I was able to just call getVideo() without adding anything to the catalog xml file.  Is there something different I need to do on the product list page since it is through a product collection? Is there a method I need to call before getVideo?

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 
nrhammond - 08 September 2008 12:49 PM

I got that working on the product view page but not on the product list page. 

I was able to just call getVideo() without adding anything to the catalog xml file.  Is there something different I need to do on the product list page since it is through a product collection? Is there a method I need to call before getVideo?

It’s possible the block controlleing list.phtml isn’t selecting that attribute.

You may have to “->addAttributeToSelect(’video’);” or “->addAttributeToSelect(’video’, ‘inner’);” in the Block. (app/code/core/Mage/catalog/block/product/list.php...if memory serves)

It’s not recommended to edit core code, but you can copy the file structure and file to edit in the Local folder as a quick way to edit a core file.

(app/code/local/Mage/catalog/block/product/list.php <-- 2nd copy of list.php to edit)

edit: fixed paths

also - make this change in list.php and see if it works:

$this->_productCollection $layer->getProductCollection();

//to

$this->_productCollection $layer->getProductCollection()->addAttrbuteToSelect('video');
 
Magento Community Magento Community
Magento Community
Magento Community
 
nrhammond
Jr. Member
 
Total Posts:  10
Joined:  2008-08-11
 

This line worked

$this->_productCollection = $layer->getProductCollection()->addAttrbuteToSelect(’video’);

Thank you!

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