Magento – Show only attributes from one particular Attribute Set group

attributes

So I have an Attribute Set called Tractor Parts and in that set I have a group called Manufacturers.

Currently I have 3 attributes in the group

  1. allis_chalmers
  2. Case
  3. john_deere

What I am trying to do is list these attributes in a tab on the product view ONLY if the attribute has a value for this product. I can pull the value off the attributes individually but this is not elegant at all, not to mention cumbersome…

I can get the attribute names from the group and get those to show in the tab. I am not sure how to go about getting the value of the attribute for the current product.

Here is the code I have at the moment

<?php
require_once 'app/Mage.php';
Mage::app();

$attributeGroupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection');

foreach ($attributeGroupCollection as $attributeGroup) {
$attributeGroup->getAttributeGroupId();
}

  $attributeCollection = Mage::getResourceModel('eav/entity_attribute_collection')
    ->setAttributeGroupFilter($attributeGroup->getAttributeGroupId());
?>
  <table class="data-table" id="product-attribute-specs-table">
        <col width="25%" />
        <col />
        <tbody>
        <?php foreach ($attributeCollection as $attribute): ?>
            <tr>
                <th class="label"><?php echo $attribute->getStoreLabel() ?></th>
                <td class="data"><?php echo ***attribute value for product*** ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
    <script type="text/javascript">decorateTable('product-attribute-specs-table')</script>

The bold Italic part is what I can't figure out. I think I need to load the product but not sure how. Any help would be greatly appreciated!!

Best Answer

100% working now, code pasted below for others to use. Not that the group ID is specified on the setAttributeGroupFilter line

<?php  
require_once 'app/Mage.php';
Mage::app();

$attributeGroupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection');
$product = $this->getProduct();

foreach ($attributeGroupCollection as $attributeGroup) {
    $attributeGroup->getAttributeGroupId();

$attributeCollection = Mage::getResourceModel('eav/entity_attribute_collection')
    ->setAttributeGroupFilter(25);      
} 
?>  

<table class="data-table" id="product-attribute-specs-table">
    <col width="25%" />
    <col />
        <tbody>
            <?php foreach ($attributeCollection as $attribute): ?>
                <?php if (!is_null($product->getData($attribute->getAttributeCode())) && ((string)$attribute->getFrontend()->getValue($product) != '')) { ?>
                    <tr>
                        <th class="label"><?php echo $attribute->getStoreLabel() ?></th>
                        <td class="data"><?php echo $attribute_value = $product->getResource()->getAttribute($attribute)->getFrontend()->getValue($product) ?></td>
                </tr>
                <?php } ?>
            <?php endforeach; ?>
         </tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table')</script> 
Related Topic