Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Listing Product Features by Attribute Group (solved)
 
jim_keller
Jr. Member
 
Total Posts:  6
Joined:  2008-11-28
 

One of our clients wanted to be able to select “Yes” or “No” from a large attribute Group, but have the “yes” attributes display in one long list, with the “No"s being omitted. So, instead of:

Feature1
Yes

Feature2
Yes

Feature3
No

They wanted:

FEATURES
Feature1
Feature2

It took a bit of digging around, but I was able to accomplish it by putting the following code in template/catalog/product/view/attributes.phtml

$listable_groups = array('Bag Features'); //The attribute groups listed here will display as a single list beneath the group name
$group_names = array();
$active_group_name null;
        
$attributes $_product->getAttributes();

foreach (
$attributes as $attribute{
   
       $new_group 
false;
   
    if (
$attribute->getIsVisibleOnFront() ) {
        $group_id 
=  $attribute->getData('attribute_set_info/' $_product->getAttributeSetId() . '/group_id');
    
        if ( !isset(
$group_names[$group_id]) ) {
    
            $group_model 
Mage::getModel('eav/entity_attribute_group');
            
$group_model->load($group_id);
    
                      
// group names are cached to prevent having to check the DB on each iteration
               
$group_names[$group_id] $group_model->getAttributeGroupName();
                        
        
}

        
if ( $group_names[$group_id] != $active_group_name {
            $active_group_name 
$group_names[$group_id];
            
$new_group true;
        
}

        $value 
$attribute->getFrontend()->getValue($_product);
        
        if ( 
in_array($active_group_name$listable_groups) ) {
                        
                       
// A "listable" attribute

            
if ( $new_group //display the heading if we're in a new group
                
            
?>
                
<div class="product-attribute-title"><?php echo $active_group_name ?></div>
        
            
<?php                
                
            }
            
            
if ( $value == 'Yes' {
            ?>
            
            
<div class="product-attribute-desc">
                 
<?php echo $this->__($attribute->getFrontend()->getLabel()) ?>
            
</div>
        
            
<?php
            }
        }
        
else {
        
                   
// A regular attribute

            
if (strlen($value) && $_product->hasData($attribute->getAttributeCode())) {
        ?>
        
            
<div class="product-attribute-title">
                
<?php echo $this->__($attribute->getFrontend()->getLabel()) ?>
             
</div>
            <
div class="product-attribute-desc">
                    
<?php echo $_helper->productAttribute($_product$value$attribute->getAttributeCode()) ?> 
             
</div>
        
<?php
            }    
        }
    }
}

Hope this can help someone out.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mrspeaker
Member
 
Total Posts:  44
Joined:  2009-01-19
 

Thanks - this was very helpful!

Just a question… is that the most effective way to do it if all you want to do is get all the attributes for a given group name? I am using your code to iterate over the attributes, load the group name (and cache it) then check if the group name is the one I’m looking for (for example “Specifications").

If it is, I store that attribute in an array.  The net result is I have all the attributes from the “Specifications” group.

Is there a better way to do this rather than hitting the db for the group names? Is there a filter or function available?

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
grooves1200
Sr. Member
 
Total Posts:  122
Joined:  2008-02-01
 

mrspeaker, do you have an example of your code for the specifications example? i’m a newbie and trying to figure out how to get attributes for a given group name.

thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
grooves1200
Sr. Member
 
Total Posts:  122
Joined:  2008-02-01
 

<<bump>>

 
Magento Community Magento Community
Magento Community
Magento Community
 
alexbucurescu
Jr. Member
 
Total Posts:  6
Joined:  2009-04-21
Bucharest, RO
 

hi!

i used your code to manage my specs tab

looks nice!

but i found a bug:

if for example i have attribute set: ‘display’ with the following labels:

- width
- height
- resolution

(in the exact order above)

If I don’t add anything to ‘width’ field (which is the first) but i add values to the other 2 fields, then the script doesn’t list my attribute set header (’display)

i think it checks only for the first field’s value then lists the set header…

support would be really appreciated

 
Magento Community Magento Community
Magento Community
Magento Community
 
cosmin_purcarea
Jr. Member
 
Total Posts:  16
Joined:  2010-09-28
 

hy,
Does anyone how do this for the filter.phtml or view.phtml attributes, i want separate attributes into their respective groups.

Image Attachments
groups.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top