Magento:从没有产品的属性集中获取属性

发布于 2024-09-10 12:10:51 字数 156 浏览 4 评论 0原文

我在我的 Magento 商店中设置了一个属性集,其中有几个二进制属性。

对于下拉列表,我需要此属性集中所有属性的列表,包括它们的内部名称和标签。由于此下拉列表应该出现在不一定选择产品的地方,因此我不能走“获取产品属性”的通常路线。

我如何获取集合中所有属性的列表?

I have set an attribute set in my Magento shop which has several binary attributes.

For a pulldown I need a list of ALL the attributes inside this one attribute set, including their internal name and their label. Since this pulldown should appear in places that not necessarily have a product selected I can't go the usual route of "getting the attributes of a product".

How do I go about of getting a list of all the attributes inside my set?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葵雨 2024-09-17 12:10:51

好吧,我意识到我错过了您想要整套属性,而不仅仅是单个属性。试试这个:

$productEntityType = Mage::getModel('eav/entity_type')->loadByCode(Mage_Catalog_Model_Product::ENTITY);

$attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection');
$attributesInfo = Mage::getResourceModel('eav/entity_attribute_collection')
    ->setEntityTypeFilter($productEntityType->getId())  //4 = product entities
    ->addSetInfo()
    ->getData();

然后,您需要迭代返回的数组,其中包含以下内容:

foreach($attributesInfo as $attribute):
    $attribute = Mage::getModel('eav/entity_attribute')->load($attribute['attribute_id']);
    echo 'label = '.$attribute->getFrontendLabel().'<br/>';
    echo 'code = '.$attribute->getAttributeCode().'<br/><br/>';
endforeach;

抱歉错过了原始点,希望这有帮助!

干杯,
京东

OK, I realised that I missed that you want the whole set of attributes, not just an individual one. Try this:

$productEntityType = Mage::getModel('eav/entity_type')->loadByCode(Mage_Catalog_Model_Product::ENTITY);

$attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection');
$attributesInfo = Mage::getResourceModel('eav/entity_attribute_collection')
    ->setEntityTypeFilter($productEntityType->getId())  //4 = product entities
    ->addSetInfo()
    ->getData();

You'll then need to iterate through the array that is returned with something like:

foreach($attributesInfo as $attribute):
    $attribute = Mage::getModel('eav/entity_attribute')->load($attribute['attribute_id']);
    echo 'label = '.$attribute->getFrontendLabel().'<br/>';
    echo 'code = '.$attribute->getAttributeCode().'<br/><br/>';
endforeach;

Sorry for missing the original point, hope this helps!

Cheers,
JD

贩梦商人 2024-09-17 12:10:51

为了获取属性集中的所有属性,可以使用 as:

$entityTypeId = Mage::getModel('eav/entity')
                ->setType('catalog_product')
                ->getTypeId();
$attributeSetName   = 'Default'; //Edit with your required Attribute Set Name
$attributeSetId     = Mage::getModel('eav/entity_attribute_set')
                    ->getCollection()
                    ->setEntityTypeFilter($entityTypeId)
                    ->addFieldToFilter('attribute_set_name', $attributeSetName)
                    ->getFirstItem()
                    ->getAttributeSetId();
$attributes = Mage::getModel('catalog/product_attribute_api')->items($attributeSetId);
foreach($attributes as $_attribute){
    print_r($_attribute);
}

Cheers!!

In order to get all the attributes in an attribute set, you can use as:

$entityTypeId = Mage::getModel('eav/entity')
                ->setType('catalog_product')
                ->getTypeId();
$attributeSetName   = 'Default'; //Edit with your required Attribute Set Name
$attributeSetId     = Mage::getModel('eav/entity_attribute_set')
                    ->getCollection()
                    ->setEntityTypeFilter($entityTypeId)
                    ->addFieldToFilter('attribute_set_name', $attributeSetName)
                    ->getFirstItem()
                    ->getAttributeSetId();
$attributes = Mage::getModel('catalog/product_attribute_api')->items($attributeSetId);
foreach($attributes as $_attribute){
    print_r($_attribute);
}

Cheers!!

一个人的旅程 2024-09-17 12:10:51

尝试这个片段,它应该给你你需要的,除了多选属性。

$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product','attribute_name');
    foreach($attribute->getSource()->getAllOptions(true,true) as $option){
        $attributeArray[$option['value']] = $option['label'];
    }
    return $attributeArray;

希望这有帮助,
京东

try this snippet, it should give you want you need, except for multi-select attributes.

$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product','attribute_name');
    foreach($attribute->getSource()->getAllOptions(true,true) as $option){
        $attributeArray[$option['value']] = $option['label'];
    }
    return $attributeArray;

Hope this helps,
JD

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文