Sor*_*rcy 2 attributes set magento drop-down-menu
我在Magento商店中设置了一个属性集,它具有多个二进制属性.
对于下拉列表,我需要一个属性集内所有属性的列表,包括它们的内部名称和标签.由于这种下拉应该出现在不一定选择产品的地方,我不能采用"获取产品属性"的通常路线.
如何获取我的集合中所有属性的列表?
好吧,我意识到我错过了你想要的整套属性,而不仅仅是个人属性.试试这个:
$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();
Run Code Online (Sandbox Code Playgroud)
然后,您需要遍历返回的数组,例如:
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;
Run Code Online (Sandbox Code Playgroud)
很抱歉错过了原点,希望这有帮助!
干杯,JD
为了获取属性集中的所有属性,您可以使用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);
}
Run Code Online (Sandbox Code Playgroud)
干杯!!