Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the attribute group in magento

Tags:

php

orm

magento

I need to get the attribute group of a certain attribute set , how can i do this ?

i think i got the attribute group id but i can't seem to get the attributes of that group.

    $attributes = $_product->getAttributes();

    foreach($attributes as $attribute)
    {
    $group_id =  $attribute->getData('attribute_set_info/' . $_product->getAttributeSetId() . '/group_id'); 
    print_r($group_id);          

    }  

I would really appreciate if somebody could help me out , thanx ;)

like image 273
jarus Avatar asked Dec 22 '22 02:12

jarus


2 Answers

Just use the ID to instantiate the model you want.

$product = Mage::getModel('catalog/product')->getCollection()->getFirstItem();
foreach($product->getAttributes() as $att)
{
    $group_id   = $att->getData('attribute_group_id');
    //Mage_Eav_Model_Entity_Attribute_Group
    $group      = Mage::getModel('eav/entity_attribute_group')->load($group_id);                
    var_dump($group);
}
like image 199
Alan Storm Avatar answered Jan 08 '23 05:01

Alan Storm


You can try this, will return all Attribute Group of Magento

$attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_group_collection')
                              ->load();

foreach ($attributeSetCollection as $id=>$attributeGroup) {
    echo 'group-name: '; echo $attributeGroup->getAttributeGroupName();
    echo '<br>';
    echo 'group-id: '; echo $attributeGroup->getAttributeGroupId();
    echo '<br>';
    echo 'set-id: '; echo $attributeGroup->getAttributeSetId();
    echo '<br>';
}
like image 27
Magefast Avatar answered Jan 08 '23 07:01

Magefast