【发布时间】:2010-07-18 09:34:07
【问题描述】:
我在我的 Magento 商店中设置了一个属性集,它有几个二进制属性。
对于下拉列表,我需要一个属性集内所有属性的列表,包括它们的内部名称和标签。由于这个下拉菜单应该出现在不一定选择产品的地方,我不能走通常的“获取产品属性”的路线。
如何获取我的集合中所有属性的列表?
【问题讨论】:
标签: attributes magento drop-down-menu set
我在我的 Magento 商店中设置了一个属性集,它有几个二进制属性。
对于下拉列表,我需要一个属性集内所有属性的列表,包括它们的内部名称和标签。由于这个下拉菜单应该出现在不一定选择产品的地方,我不能走通常的“获取产品属性”的路线。
如何获取我的集合中所有属性的列表?
【问题讨论】:
标签: attributes magento drop-down-menu set
好的,我意识到我错过了您想要整套属性,而不仅仅是单个属性。试试这个:
$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;
很抱歉错过了原点,希望对您有所帮助!
干杯, 京东
【讨论】:
为了获取一个属性集中的所有属性,可以使用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);
}
干杯!!
【讨论】:
试试这个sn-p,它应该给你想要的,除了多选属性。
$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;
希望这会有所帮助, 京东
【讨论】: