Magento:如何获取属于属性集的属性?

Magento:如何获取属于属性集的属性?,magento,Magento,有了一个属性集,我如何获得它所包含的属性列表(或者更好的是,只是不属于默认属性集的自定义属性) 属性集本身可以通过多种方式获得,例如: $entityTypeId = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId(); $attributeSet = Mage::getResourceModel('eav/entity_attribute_set_collection')->setEnti

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

属性集本身可以通过多种方式获得,例如:

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

请注意,我需要使用属性集,因此从产品中获取属性列表并不是我要寻找的解决方案。

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

Mage::getModel('catalog/product_attribute_set_api')->items($setId);
该类是
Mage\u Catalog\u Model\u Product\u Attribute\u Api
它似乎有两种方法。items()方法似乎按照您的要求执行,即“从指定的属性集检索属性”

我希望这有帮助:)

获取属性集本身

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

获取属性集中的属性。

关于属性集,下面的博客文章中收集了大量代码片段:

希望你会发现它们有用。
谢谢

我一直在寻找答案,我找不到答案,我用这些句子解决了我的问题

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

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

/** @var Mage_Catalog_Model_Product $product **/
$attributes = $product->getTypeInstance(true)->getSetAttributes($product);
如果没有:

$attributes = Mage::getModel('catalog/product')->getResource()
  ->loadAllAttributes()
  ->getSortedAttributes($attributeSetId);
正确的方法:

$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
->setAttributeSetFilter($attributeSetId)
->getItems();
var_dump($attributes);
您可以更改资源“目录/产品属性\集合”(客户,…)
设置ID$attributesteid

我想你的意思是
Mage::getModel('catalog/product_attribute_api')->items($setId)
…attribute\u set\u api
将给出一个
图像目录\u模型\u产品\u attribute\u set\u api
,对吗?
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
->setAttributeSetFilter($attributeSetId)
->getItems();
var_dump($attributes);