1

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

1 Answer 1

2

Here 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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.