通过Magento中的attribute_code获取属性模型

vie*_*ean 20 magento

我怎么能在Magento 得到Attribute model(来自:eav_attribute表格)attribute_code
注意:
- 我不在乎什么是entity_type.
非常感谢.

小智 53

您必须知道,entity_type因为您可以attribute_code为不同的实体拥有相同的内容.所以要获得属性模型:

$attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode($entity_type, $attributeCode);
Run Code Online (Sandbox Code Playgroud)

$entity_type参数可以是numeric(id直接),string(例如'catalog_product'Mage_Catalog_Model_Product::ENTITY)或它可以是模型的实例Mage_Eav_Model_Entity_Type

  • 使用常量的版本: $_attr = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, $attributeCode); (7认同)