1.加载某个attribute:
$attributeCode=Mage::getModel('catalog/resource_eav_attribute')
->load($attrbuteId)
->getData("attribute_code");
2.获取某个attribute的所有option:
$attributeObject=Mage::getModel('eav/config')->getAttribute('catalog_product')->load($attributeId);
$options = $attributeObject->setStoreId(Mage::app()->getStore()->getId())->getSource()->getAllOptions(false);
$table = $attributeObject->getBackend()->getTable();
public function getAttributeOptionsByAttributeCode($entityType, $attributeCode){
$entityType = Mage::getSingleton('eav/config')->getEntityType($entityType);
$attributeObject = Mage::getModel('customer/attribute')->loadByCode($entityType, $attributeCode);
return $attributeObject->setStoreId(Mage::app()->getStore()->getId())->getSource()->getAllOptions(false);
}
或者:
$optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setAttributeFilter($attr_model->getId())
->setStoreFilter($storeId, false)
->load();
3.获取某个attribute的所有多语言label:
$attributeLabelsArray= Mage::getResourceModel('eav/entity_attribute')
->getStoreLabelsByAttributeId($attrbuteId);
4.获取所有的产品属性的attribute:
$attributes = Mage::getResourceModel ( 'catalog/product_attribute_collection' )
->addFieldToFilter ( "frontend_input", "select" )
->load ();
5.获取某个product的所有attribute:
注:如果是在collection中获取自定义的attribute,必须加addAttributeToSelect(), 如下:
product=Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect("dropdownlistone");
6. 获取某个种类的所有attribute:
$entityTypeId = Mage::getSingleton('eav/config')
->getEntityType('catalog_product')
->getEntityTypeId();
$items = Mage::getResourceSingleton('catalog/product_attribute_collection')
->setEntityTypeFilter($entityTypeId)
->getItems();
7.获取某个attribute_set的所有attribute:
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
->setAttributeSetFilter($attribute_set_id)
->load();
$attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection')
->load();
8。 获取attribute 对象 by attribute code
$muarqspFrom = Mage::getSingleton('eav/config')->getAttribute('catalog_product', '
muarqsp_from');
$attrCollection = Mage::getResourceModel('eav/entity_attribute_collection')
->setCodeFilter($attributeCode)
->load();
[文章标题] magento中的attribute 总结
[文章作者]曾健生
[作者邮箱]zengjiansheng1@126.com
[作者QQ]190678908
[博客] http://blog.youkuaiyun.com/newjueqi