magento 根据attribute code/id获取attribute对象 及options
2013-05-15 16:13
429 查看
$attributes = Mage::getModel('catalogsearch/advanced')->getAttributes(); $attributeArray=array(); foreach($attributes as $a){ if($a->getAttributeCode() == 'desired_attribute_code'){ foreach($a->getSource()->getAllOptions(false) as $option){ $attributeArray[$option['value']] = $option['label']; } } }
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'attribute_id');foreach ( $attribute->getSource()->getAllOptions(true, true) as $option){$attributeArray[$option['value']] = $option['label'];}
获取multi-select的属性值:
$attributeId = Mage::getResourceModel('eav/entity_attribute') ->getIdByCode('catalog_product','attribute_code_here'); $attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId); $attributeOptions = $attribute ->getSource()->getAllOptions();获取某产品的属性的值:
$_product->getResource()->getAttribute('club_type')->getFrontend()->getValue($_product)
根据attribute code获取attribute属性对象:
Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'price');
获取某个dropdown的所有属性值
$collection = Mage::getResourceModel('eav/entity_attribute_option_collection') ->setPositionOrder('asc') ->setAttributeFilter($attributeId) ->setStoreFilter(null);
或者:
$attributesInfo = Mage::getResourceModel('eav/entity_attribute_collection') ->setEntityTypeFilter({entityType}) ->setCodeFilter($attributes) ->addSetInfo() ->getData();
参考: http://www.sharpdotinc.com/mdost/2009/04/06/magento-getting-product-attributes-values-and-labels/
相关文章推荐
- [Magento SQL]根据某个rule_id获取已经使用的coupon_code
- jquery1.5.1根据元素ID获取元素对象
- Java根据sessionId获取Session对象
- magento中根据用户的id获取用户的所有订单以及每个订单中的物品 以及物品的相关属性
- 使用dojo declare(继承v102版本) 时出现无法根据id获取到对象的问题
- flex内根据id(string)获取对象
- jQuery根据ID、CLASS、等获取对象
- jQuery根据ID、CLASS、等获取对象
- 为什么Jquery有时候根据模板中控件的Id但是获取不到该控件的对象
- jQuery根据ID、CLASS、等获取对象
- a573 js中根据元素名获取对象,根据id获取等等。。。
- Java根据sessionId获取Session对象
- magento 根据分类ID或名称获取该分类下的子分类
- EASBOS根据id获取对象方法来进行过滤字段
- Magento中获取Attribute_code并获取客户端显示的值
- 获取json对象的id或者根据name获取id
- jQuery根据ID、CLASS、等获取对象的实例
- jquery1.5.1中根据元素ID获取元素对象的代码
- 根据dom对象或其id获取对象位置的代码
- jquery1.5.1中根据元素ID获取元素对象的代码