Get attribute value in product view page
If you are in the product view page, in the catalog/product/view.phtml
there is an instance of the product model usually called $_product
.
From this variable you have access to all the attribute products by the getter methods.
If you want to display the value on the page you have to use the echo php command.
echo "Brand is " . $_product->getData("attribute_code");
or
echo "Brand is " . $_product->getAttributeCode();
If you have a "dropdown" attribute type getData()
and it will return the id
of the option. If you need the label of the dropdown you can use the
echo "Brand is " . $_product->getAttributeText("attribute_code");
If I understand your quest correctly you are trying to get attribute value on the product page.
This should give you the result:
$_product->getAttributeText('my_attribute');
Assumption $_product
is an object and already initiated before calling the above code.
Check some more info regarding attribute:
/**
* get attribute collection
*/
$attribute = $_product->getResource()->getAttribute('my_attribute');
/**
* get attribute type
*/
$attribute->getAttributeType();
/**
* get attribute Label
*/
$attribute->getFrontendLabel();
/**
* get attribute default value
*/
$attribute->getDefaultValue();
/**
* check if the attribute is visible
*/
$attribute->getIsVisible();
/**
* check if the attribute is required
*/
$attribute->getIsRequired();
/**
* get attribute value
*/
$attributeValue = Mage::getModel('catalog/product')->load($_product->getId())->getMyAttribute();
More reading: http://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-value/
[UPDATE]
To get brand in product view page you have to do this:
- Go to admin then catalog > attribute > manage attribute
- Then search
manufacturer
and edit that - Set
Visible on Product View Page on Front-end
to YES
This will make sure it is visible in the frontend.