magento 根据attribute code/id获取attribute对象 及options

$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/



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值