magento中的attribute 总结

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.csdn.net/newjueqi




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

newjueqi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值