Here is a quick code to get all attributes and their name and value associated with any particular product.
First of all we have to load the product by it’s ID. And then get all it’s attributes. Here is the code:-
$productId = 52;
$product = Mage::getModel('catalog/product')->load($productId);
$attributes = $product->getAttributes();
Get Name and Value of all attributes of a product
// get all attributes of a product
foreach ($attributes as $attribute) {
$attributeCode = $attribute->getAttributeCode();
$label = $attribute->getStoreLabel($product);
$value = $attribute->getFrontend()->getValue($product);
echo $attributeCode . '-' . $label . '-' . $value; echo "<br />";
}
Get Name and Value of only frontend attributes of a product
//get only frontend attributes of a product
foreach ($attributes as $attribute) {
if ($attribute->getIsVisibleOnFront()) {
$attributeCode = $attribute->getAttributeCode();
$label = $attribute->getFrontend()->getLabel($product);
$value = $attribute->getFrontend()->getValue($product);
echo $attributeCode . '-' . $label . '-' . $value; echo "<br />";
}
}
Get Name and Value of any particular attribute of a product
// get name and value of particular attribute of a product
foreach ($attributes as $attribute) {
$attributeCode = $attribute->getAttributeCode();
$code = 'color';
if ($attributeCode == $code) {
$label = $attribute->getStoreLabel($product);
$value = $attribute->getFrontend()->getValue($product);
echo $attributeCode . '-' . $label . '-' . $value;
}
}
Hope it helps. Thanks.