Get Attributes by attribute group name in magento

2 comments
Sometimes, we need to create attribute group for additional information to show on product detail page or needed to create attributes for sidebar filters on product listing page. Here in this post, I am going to share with you some lines of codes that will surely help you to call/show additional information group attributes on your product detail page.


<?php 
         $setId = $_product->getAttributeSetId();
         $additional_info = Mage::getModel('eav/entity_attribute_group')
            ->getResourceCollection()
            ->setAttributeSetFilter($setId)
            ->setSortOrder()
            ->load();
        foreach ($additional_info as $info):
        if($info->getAttributeGroupName() == 'Additional Information'){ 
            $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
                ->setAttributeGroupFilter($info->getId())
                ->addVisibleFilter()
                ->checkConfigurableProducts()
                ->load();
            if ($attributes->getSize() > 0) {
            ?>
            <div class="box-collateral box-additional">
            <h2><?php echo $this->__('Additional Information') ?></h2>
            <table class="data-table" id="product-attribute-specs-table">
            <col width="25%" />
            <col />
            <tbody> 
                <?php     
            foreach ($attributes->getItems() as $attribute) {
                //print_r($attribute);die;
            ?>
            <tr>
                <th class="label"><?php echo $attribute->getFrontendLabel(); ?></th>
                <td class="data"><?php $attr_val = Mage::getModel('catalog/product')
   ->load($_product->getId())
   ->getAttributeText($attribute->getAttributeCode());
                        if(is_array($attr_val)){echo implode(",",$attr_val);}else{echo $attr_val;} ?></td>
            </tr>
            <?php }?>
                </tbody>
            </table>
            <script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
        </div>
        <?php }} endforeach; ?>

Here In this tutorial, I have created an attribute set with the name ‘Additional Information’ and added the attributes in this attribute set. And then applied to this sets on my products. Note that attribute sets can only be applied while adding new products. If you have already created your products then you have to delete your existing product then recreate all your products by choosing your needed attribute set.

I hope this simple tutorial will help. Thank you reading my post. Please write your opinion in the comment box below or if you encountered any issues while working on attribute sets then feel free to ask your questions in the comment box below.

2 comments :

  1. Replies
    1. If you want to show attributes on product detail page.

      app->design->frontend->template_dir->default->template->catalog->product->view.phtml

      Delete