2011-07-27 124 views
7

有一个属性集,我如何获得它包含的属性列表(或者更好的是,只是不属于默认属性集的自定义属性)?Magento:如何获取属性集属性?

设置本身可以通过多种方式获得的属性,如:我需要使用设置属性

$entityTypeId = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId(); 
$attributeSet = Mage::getResourceModel('eav/entity_attribute_set_collection')->setEntityTypeFilter($entityTypeId)->addFilter('attribute_set_name', 'Default'); 

注意,所以从产品得到的属性列表是不是我的解决办法寻找。

回答

6

我相信答案就在这个模型中

Mage::getModel('catalog/product_attribute_set_api')->items($setId); 

类是Mage_Catalog_Model_Product_Attribute_Api它似乎有两种方法。该项目()方法似乎做什么你问即“检索指定属性的属性设置为”

我希望帮助:)

+9

我想你的意思是'法师:: getModel('catalog/product_attribute_api') - > items($ setId );','... attribute_set_api'会给出一个'Mage_Catalog_Model_Product_Attribute_Set_Api',对吗? –

16
Mage::getModel('catalog/product_attribute_set_api')->items(); 

获取属性设置自己。

Mage::getModel('catalog/product_attribute_api')->items($setId); 

获取属性的属性设置。

1

我一直在寻找答案,我could'nt找到它,我解决了我的问题与这些行;

 $attributeSetId = /* set id */; 
     $attributes = array(); 

     $groups = Mage::getModel('eav/entity_attribute_group') 
      ->getResourceCollection() 
      ->setAttributeSetFilter($attributeSetId) 
      ->setSortOrder() 
      ->load(); 

     foreach ($groups as $node) { 

      $nodeChildren = Mage::getResourceModel('catalog/product_attribute_collection') 
       ->setAttributeGroupFilter($node->getId()) 
       //->addFieldToFilter('is_user_defined', true) # I was trying to get user defined attributes. 
       ->addVisibleFilter() 
       ->load(); 

      if ($nodeChildren->getSize() > 0) { 
       foreach ($nodeChildren->getItems() as $child) { 
        $attr = array(
         'id'    => $child->getAttributeId(), 
         'text'    => $child->getAttributeCode() 
        ); 

        $attributes[] = $attr; 
       } 
      } 
     } 

     var_dump($attributes); 
2

您不一定需要访问API类。有一种更自然的方法可用。如果你有一个产品:

/** @var Mage_Catalog_Model_Product $product **/ 
$attributes = $product->getTypeInstance(true)->getSetAttributes($product); 

如果不是:

$attributes = Mage::getModel('catalog/product')->getResource() 
    ->loadAllAttributes() 
    ->getSortedAttributes($attributeSetId); 
6

正确的做法:

$attributes = Mage::getResourceModel('catalog/product_attribute_collection') 
->setAttributeSetFilter($attributeSetId) 
->getItems(); 
var_dump($attributes); 

你可以改变资源 '目录/ product_attribute_collection'(客户,...) And Set ID $ attributeSetId