What is the best way to hide an empty attribute in the front end, and Display attributes group names if that group has an attribute showing in the front end.
EX:
Group Name
Attribute: Sample text
Attribute: Sample text
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityHere is the code:
<?php
// From product view page (catalog/product/view.phtml)
$attributeSetId = $_product->getAttributeSetId();
$groups = Mage::getModel('eav/entity_attribute_group')
->getResourceCollection()
->setAttributeSetFilter($attributeSetId)
->setSortOrder()
->load();
$groupAttributeValues = array();
foreach ($groups as $group) {
$groupName = $group->getAttributeGroupName();
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
->setAttributeGroupFilter($group->getId())
->addVisibleFilter()
->checkConfigurableProducts()
->load();
if ($attributes->getSize() > 0) {
foreach ($attributes->getItems() as $attribute) {
$attributeCode = $attribute->getAttributeCode();
$attributeLabel = $attribute->getFrontendLabel();
$attributeValue = $_product->getData($attributeCode);
if ($attributeValue != '') { //check other condition if you want to
$groupAttributeValues[$groupName][$attributeLabel] = $attributeValue;
}
}
}
}
Zend_Debug::dump($groupAttributeValues);