如何在magento中获取属性组

时间:2010-06-22 05:38:35

标签: php orm magento

我需要获取某个属性集的属性组,我该怎么做?

我认为我得到了属性组ID,但我似乎无法获得该组的属性。

    $attributes = $_product->getAttributes();

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

    }  

如果有人可以帮助我,我真的很感激,不仅仅是;)

2 个答案:

答案 0 :(得分:7)

只需使用ID来实例化您想要的模型。

$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);
}

答案 1 :(得分:4)

你可以尝试这个,将返回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>';
}