I'm trying to figure out a way to best display custom attributes on the product view page.
Currently I'm doing something like this:
if (($_product->getCollectionName()) && ($_product->getResource()->getAttribute('collection_name')->getIsVisibleOnFront() == '1'))
{
echo $_product->getResource()->getAttribute('collection_name')->getFrontendLabel() . ': ' . $_product->getCollectionName();
}
if (($_product->getColor()) && ($_product->getResource()->getAttribute('color')->getIsVisibleOnFront() == '1'))
{
echo $_product->getResource()->getAttribute('color')->getFrontendLabel() . ': ' . $_product->getColor();
}
This continues for all 95 custom attributes.
Does Magento have any built-in functions to simplify this code? Is there a way to loop through all the attributes assign to the product?
A few things to keep in mind:
- I need to check if the attribute is set to visible on the frontend
- I need to show the attribute label only when the attribute has a value for the product
- Attributes vary in type - text, multi-select, dropdown...