cancel
Showing results for 
Search instead for 
Did you mean: 

How to list all attributes for a product where the attribute has a value

How to list all attributes for a product where the attribute has a value

Sorry for the dumb questions, I am very new to Magento and have found it to be sort of difficult to wrap my brain around.

I'm trying to make my custom tab show all attributes for a product, and the value for that attribute.  For example, if the product is a size 10 brown shoe, and there are two attributes (size and color) I just want the tab to show size: 10, color: brown.

I have been frankenstein coding without knowing what I am doing and have managed to show a list of all attributes. but I don't know how to get the value of that attribute to display too. Here's my code so far:

$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
->getItems();

foreach ($attributes as $attribute){

echo '<div class="std">';
echo $attribute->getFrontendLabel();
echo ': ';
$productAttributeCode=$attribute->getAttributeCode();
echo $attribute->getAttributeText($productAttributeCode); //this is where I am confused, I am not retrieving the value
echo '</div>';

}

Any help would be greatly appreciated. Thank you so much in advance!

1 REPLY

Re: How to list all attributes for a product where the attribute has a value

Ok I figured out my problem. I never invoked the product object. The working code is as follows:


$_helper = $this->helper('catalog/output');
$_product = $this->getProduct();
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
->getItems();

foreach ($attributes as $attribute){

$productAttributeCode=$attribute->getAttributeCode();
$productAttributeData=$_product->getData($productAttributeCode);

if ($productAttributeData > ""){
if ($productAttributeCode != "status"){
echo '<div class="std">';
echo $attribute->getFrontendLabel();
echo ': ';
//echo $productAttributeCode;
//echo ': ';
echo $productAttributeData;
echo '</div>';
}
}
}