Как я могу получить Attribute model
(from: eav_attribute
таблица) attribute_code
в Magento?
Примечание:
- Мне все равно, что такое entity_type.
Большое вам спасибо.
Получить модель атрибута по атрибуту_код в Magento
Ответ 1
Вы должны знать entity_type
, потому что у вас может быть тот же attribute_code
для разных объектов. Итак, чтобы получить модель атрибута:
$attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode($entity_type, $attributeCode);
$entity_type
может быть numeric
(id напрямую), string
(например, "catalog_product" ) или может быть экземпляром модели Mage_Eav_Model_Entity_Type
Ответ 2
Возможно, вы можете прочитать атрибуты путем фильтрации коллекции
Mage::getModel('eav/entity_attribute')->getCollection()->addFieldToFilter('attribute_code', array('in' => $codes) )
Так как мне нужны атрибуты из Продукта по коду, я делаю это так:
$codes = (array) $codes;
$res = array_intersect_key($this->getAttributes(), array_flip($codes));
$code - это атрибут_код-массив Область действия: расширенный Mage_Catalog_Model_Product
Ответ 3
$attribute_code = "flat_printing_quantity";
$attribute_details =
Mage::getSingleton("eav/config")->getAttribute('catalog_product', $attribute_code);
$attribute = $attribute_details->getData();
echo $attribute['attribute_id'];
Ответ 4
$attributeModel = Mage:: getModel ('eav/entity_attribute') → loadByCode (1, 'is_approved'); echo $attributeModel- > getAttributeId();