【问题标题】:how to get the attribute group in magento如何在magento中获取属性组
【发布时间】:2010-06-22 05:38:35
【问题描述】:

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

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

    $attributes = $_product->getAttributes();

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

    }  

如果有人可以帮助我,我将不胜感激,thanx ;)

【问题讨论】:

    标签: php orm magento


    【解决方案1】:

    只需使用 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);
    }
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多